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

compile and pack electron main thread js files in order to reduce the size of app.asar #11772

Open
bthulu opened this issue Dec 24, 2021 · 0 comments

Comments

@bthulu
Copy link

bthulu commented Dec 24, 2021

Is your feature request related to a problem? Please describe.
i add nothing to dependencies in package.json except render dependencies such as follows:

  "dependencies": {
    "@quasar/extras": "^1.0.0",
    "axios": "^0.21.1",
    "core-js": "^3.6.5",
    "quasar": "^2.0.0",
    "vue-i18n": "^9.0.0",
    "vuex": "^4.0.1"
  }

after execute quasar build -m electron, all my files in src folder and render dependencies is compiled and repackaged to dist/electron/UnPackaged/js folder. so, just need to add all files in dist/electron/UnPackaged/js/ to app.asar, no other dependencies needed.

however, all dependencies in node_modules except dev dependencies is added to app.asar, makes app.asar grows to 15MB+.

then i add the following into quasar.conf.js, reduced app.asar to only 1MB+, and everything works.

electron {
  bundler: 'builder',
  builder: {
    files: [
      '**/*',
      '!**/node_modules/**/*',
    ],
  }
}

so no need to add any render dependencies in node_modules to app.asar, since all render dependencies has been tree-shaking and repacked to dist/electron/UnPackaged/js/, just add files in this folder to app.asar is ok.

in the real world, we will add some dependencies to the main process. eg, add electron-updater and use it in electron-main.js.

but if i build electron use the config above, then install and run, it will crash and tell you can not find electron-updater. it seems only copied files in src-electron , no repackage and tree-shaking on them with their dependencies.

finally, i find all atomic dependencies electron-updater needs, and add them to files tag in quasar.conf.js as below, rebuild electron, the app.asar grows to 2MB+, and everything works.

        files: [
          '**/*',
          '!**/node_modules/**/*',
          // all electron-updater and its dependencies
          '**/node_modules/electron-updater/**/*',
          '**/node_modules/builder-util-runtime/**/*',
          '**/node_modules/fs-extra/**/*',
          '**/node_modules/@types/semver/**/*',
          '**/node_modules/js-yaml/**/*',
          '**/node_modules/lazy-val/**/*',
          '**/node_modules/lodash.escaperegexp/**/*',
          '**/node_modules/lodash.isequal/**/*',
          '**/node_modules/semver/**/*',
          '**/node_modules/debug/**/*',
          '**/node_modules/sax/**/*',
          '**/node_modules/jsonfile/**/*',
          '**/node_modules/universalify/**/*',
          '**/node_modules/argparse/**/*',
          '**/node_modules/lru-cache/**/*',
          '**/node_modules/yallist/**/*',
          '**/node_modules/ms/**/*',
          '**/node_modules/universalify/**/*',
          '**/node_modules/graceful-fs/**/*',
        ],

then if i need more dependencies for the main process, and i don't want to include all render dependencies duplicate to make xxx.exe too big, how could i do ? find all final atomic dependencies, and add them to files?

i also tried electron-packager, the problem is the same as electron-builder.

Describe the solution you'd like
repackage and tree-shaking main process js files with only their dependencies while run quasar build -m electron

Describe alternatives you've considered
add a quasar add electronMainDependencies xxx command, when execute it, add the dependencies to a electronMainDependencies tag in package.json and deliver its value to quasar.conf.js, so i can include them in files and exclude all other files in node_modules.

Additional context

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

1 participant