Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vite-typescript]: need to set cacheDir by default? #3298

Closed
BlackHole1 opened this issue Aug 16, 2023 · 3 comments
Closed

[vite-typescript]: need to set cacheDir by default? #3298

BlackHole1 opened this issue Aug 16, 2023 · 3 comments

Comments

@BlackHole1
Copy link
Member

BlackHole1 commented Aug 16, 2023

The following discussion is from PR: #3178. In order to facilitate the discussion and make it easier for other community members to participate, I have created this issue to track this problem.


erikian:
Looks like Vite's default cache directory is node_modules/.vite, so we end up packaging that folder along with the project dependencies when building the project. Do you think it would be possible to use cacheDir: './.vite' as the default in the Vite configs, either here or maybe directly in the Vite plugin?

caoxiemeihao:
The directory node_modules/.vite is esbuild Pre-Bundling cache dir, it's only work vite serve phase and ignored vite build phase by default. (@electron-forge/plugin-vite just run vite build)
Even if it is used in the vite build phase, it is rebuild by Vite into the dist folder.

erikian:

The directory node_modules/.vite is esbuild Pre-Bundling cache dir

That's why we don't need it in node_modules when the app is packaged - the contents of this folder are not necessary for the app to run, but it's being included anyway 😅

In my case, I tested the template with a hello world React app (just electron-squirrel-startup, react and react-dom as dependencies), and my out/<project_name>/resources/app/node_modules/.vite folder was about 2.5 MB. No big deal, but I'm thinking it might become more of a problem for larger apps with multiple dependencies, so it might be worth addressing that somehow (maybe just deleting the folder from node_modules before packaging or using the packageAfterCopy hook could do the trick here).

That being said, I have zero experience with Vite and I don't how large this folder can get - if it never exceeds a couple megabytes, it might not be worth the hassle.


Originally posted in #3178 (comment)

@BlackHole1
Copy link
Member Author

/cc @caoxiemeihao @erikian @GitMurf @ronaldcurtis

@caoxiemeihao
Copy link
Member

image image

In my case, node_modules is not included in the built app directory, even if we need some runtime dependencies to build with node_modules, node_modules/.vite is not included in the final app directory.

Of course, this Demo uses electron-builder, I have not had time to replace it with forge, I will try to replace it with forge later.

Demo 👉 https://github.com/electron-vite/electron-vite-vue

@caoxiemeihao
Copy link
Member

Fixed in #3336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants