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

The size of the exe packaged by forge is ridiculously large. I think this is caused by not using vite build to build the dist directory. Also, all dependencies of dependent libraries are packaged, without distinguishing between used and unused ones. #3420

Closed
3 tasks done
xhc-code opened this issue Nov 20, 2023 · 3 comments

Comments

@xhc-code
Copy link

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.1

Electron version

27.1

Operating system

win10

Last known working Electron Forge version

No response

Expected behavior

The dist directory built by forge using vite

Actual behavior

Hello, I used electron-forge to package the vite practice project into an exe. The dist directory built through npm run build is only 108kb. But the asar file built through electron-forge reaches 18mb. Is this because I haven't configured it? Or is this how the packager works, without using the dist directory built by vite.

The size of the exe packaged by forge is ridiculously large. I think this is caused by not using vite build to build the dist directory. Also, all dependencies of dependent libraries are packaged, without distinguishing between used and unused ones.

Steps to reproduce

none

Additional information

My project structure:
root
electron: Place main.js and preload.js of electron
src: Place the files of vue and main.js (vue).
index.html file
...
forge.config.js content

module.exports = {
   packagerConfig: {
     asar: true,
     productName: "APp",
   },
   rebuildConfig: {},
   makers: [
     {
       name: '@electron-forge/maker-squirrel',
       config: {},
     },
     {
       name: '@electron-forge/maker-zip',
       platforms: ['darwin'],
     },
     {
       name: '@electron-forge/maker-deb',
       config: {},
     },
     {
       name: '@electron-forge/maker-rpm',
       config: {},
     },
   ],
   plugins: [
     {
       name: '@electron-forge/plugin-auto-unpack-natives',
       config: {},
     },
     {
       name: '@electron-forge/plugin-vite',
       config: {
         // `build` can specify multiple entry builds, which can be
         // Main process, Preload scripts, Worker process, etc.
         build: [
           {
             // `entry` is an alias for `build.lib.entry`
             // in the corresponding file of `config`.
             entry: 'main.js',
             config: 'vite.main.config.js'
           },
           {
             entry: 'preload.js',
             config: 'vite.preload.config.js'
           }
         ],
         renderer: [
           {
             name: 'main_window',
             config: 'vite.renderer.config.js'
           }
         ]
       }
     }
   ],
};

@michalakis
Copy link

michalakis commented Nov 23, 2023

Hi, I had a similar issue, in my case, there were unnecessary files in the project that were being added to the .exe, once I told forge to exclude them the .exe size decreased significantly .

All I had to do was add the ignore option to packagerConfig in forge.config.js

It takes a regex object or array of regex objects, in my case it looks like this:

packagerConfig: {
 ignore: [/\.angular$/, /src$/];
}

of course you are using vite, I dont know if that means you have to place this somewhere else

@Viiprogrammer
Copy link

Check my answer in the related question - #3423 (comment)

@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

5 participants