Skip to content

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

@BlackHole1

Description

@BlackHole1

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions