Skip to content

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

Closed

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)

Activity

  1. BlackHole1 commented on Aug 16, 2023

    @BlackHole1
    MemberAuthor
  2. caoxiemeihao commented on Aug 16, 2023

    @caoxiemeihao
    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

  3. caoxiemeihao commented on Jan 17, 2024

    @caoxiemeihao
    Member

    Fixed in #3336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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