From f8dabb999c0b7bcf825c29876899f310b59ad130 Mon Sep 17 00:00:00 2001 From: leejooy96 Date: Mon, 24 Oct 2022 18:15:45 +0900 Subject: [PATCH] pack: do not include optional values for the builder files rule --- docs/build-configuration.md | 33 +++++++++++++++++++++++++++++++-- electron-builder.json5 | 23 +---------------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/docs/build-configuration.md b/docs/build-configuration.md index c76f8dd..4eb8fdd 100644 --- a/docs/build-configuration.md +++ b/docs/build-configuration.md @@ -15,7 +15,7 @@ $ npm run build:linux The built packages can be found in `dist/release/{version}` location. -### Build settings for projects that use Native Node modules +## Build settings for projects that use Native Node modules For projects that use the **Native Node Module**, add the following script to your package.json: When installing dependencies, electron-builder will take care of any modules that require rebuilding. @@ -29,7 +29,7 @@ For projects that use the **Native Node Module**, add the following script to yo For more information, please refer to the following article: https://webpack.electron.build/dependency-management#installing-native-node-modules -### What do I need to do for a multi-platform build? +## What do I need to do for a multi-platform build? **macOS** is recommended if you want to build multiple platforms simultaneously on one platform. Because it can be configured with just a few very simple settings. @@ -40,3 +40,32 @@ $ npm run build ``` `Multipass` configuration may be required for Linux builds. Learn more about `Multipass` through the following link: https://multipass.run + +## Reduce bundle size by excluding development files + +You can exclude files you don't need at build time by adding a file pattern to the files property of electron-builder.json5. This will save bundle capacity. + +Below is an unnecessary `node_modules` file pattern that can further save bundles. Depending on the project, using the rules below may cause problems, so please review it before using. + +```json5 +[ + '!**/.*', + '!**/node_modules/**/{CONTRIBUTORS,CNAME,AUTHOR,TODO,CONTRIBUTING,COPYING,INSTALL,NEWS,PORTING,Makefile,htdocs,CHANGELOG,ChangeLog,changelog,README,Readme,readme,test,sample,example,demo,composer.json,tsconfig.json,jsdoc.json,tslint.json,typings.json,gulpfile,bower.json,package-lock,Gruntfile,CMakeLists,karma.conf,yarn.lock}*', + '!**/node_modules/**/{man,benchmark,node_modules,spec,cmake,browser,vagrant,doxy*,bin,obj,obj.target,example,examples,test,tests,doc,docs,msvc,Xcode,CVS,RCS,SCCS}{,/**/*}', + '!**/node_modules/**/*.{conf,png,pc,coffee,txt,spec.js,ts,js.flow,html,def,jst,xml,ico,in,ac,sln,dsp,dsw,cmd,vcproj,vcxproj,vcxproj.filters,pdb,exp,obj,lib,map,md,sh,gypi,gyp,h,cpp,yml,log,tlog,Makefile,mk,c,cc,rc,xcodeproj,xcconfig,d.ts,yaml,hpp}', + '!**/node_modules/**/node-v*-x64{,/**/*}', + '!**/node_modules/bluebird/js/browser{,/**/*}', + '!**/node_modules/bluebird/js/browser{,/**/*}', + '!**/node_modules/source-map/dist{,/**/*}', + '!**/node_modules/lodash/fp{,/**/*}', + '!**/node_modules/async/!(dist|package.json)', + '!**/node_modules/async/internal{,/**/*}', + '!**/node_modules/ajv/dist{,/**/*}', + '!**/node_modules/ajv/scripts{,/**/*}', + '!**/node_modules/node-pre-gyp/!(lib|package.json)', + '!**/node_modules/node-pre-gyp/lib/!(util|pre-binding.js|node-pre-gyp.js)', + '!**/node_modules/node-pre-gyp/lib/util/!(versioning.js|abi_crosswalk.json)', + '!**/node_modules/source-map-support/browser-source-map-support.js', + '!**/node_modules/json-schema/!(package.json|lib)' +] +``` diff --git a/electron-builder.json5 b/electron-builder.json5 index 8d867e0..9be0e76 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -13,33 +13,12 @@ /* A list of files not to be included in the build. */ files: [ /* - (Recommended) The files and folders listed below should not be included in the build. + (Required) The files and folders listed below should not be included in the build. */ 'dist/**/*', '!docs/**/*', '!dist/release/**/*', '!dist/main/index.ts', - '!**/.*', - /* - (Optional) Please review the list below based on your project preferences, as you may need to include them as needed. - */ - '!**/node_modules/**/{CONTRIBUTORS,CNAME,AUTHOR,TODO,CONTRIBUTING,COPYING,INSTALL,NEWS,PORTING,Makefile,htdocs,CHANGELOG,ChangeLog,changelog,README,Readme,readme,test,sample,example,demo,composer.json,tsconfig.json,jsdoc.json,tslint.json,typings.json,gulpfile,bower.json,package-lock,Gruntfile,CMakeLists,karma.conf,yarn.lock}*', - '!**/node_modules/**/{man,benchmark,node_modules,spec,cmake,browser,vagrant,doxy*,bin,obj,obj.target,example,examples,test,tests,doc,docs,msvc,Xcode,CVS,RCS,SCCS}{,/**/*}', - '!**/node_modules/**/*.{conf,png,pc,coffee,txt,spec.js,ts,js.flow,html,def,jst,xml,ico,in,ac,sln,dsp,dsw,cmd,vcproj,vcxproj,vcxproj.filters,pdb,exp,obj,lib,map,md,sh,gypi,gyp,h,cpp,yml,log,tlog,Makefile,mk,c,cc,rc,xcodeproj,xcconfig,d.ts,yaml,hpp}', - '!**/node_modules/**/node-v*-x64{,/**/*}', - '!**/node_modules/bluebird/js/browser{,/**/*}', - '!**/node_modules/bluebird/js/browser{,/**/*}', - '!**/node_modules/source-map/dist{,/**/*}', - '!**/node_modules/lodash/fp{,/**/*}', - '!**/node_modules/async/!(dist|package.json)', - '!**/node_modules/async/internal{,/**/*}', - '!**/node_modules/ajv/dist{,/**/*}', - '!**/node_modules/ajv/scripts{,/**/*}', - '!**/node_modules/node-pre-gyp/!(lib|package.json)', - '!**/node_modules/node-pre-gyp/lib/!(util|pre-binding.js|node-pre-gyp.js)', - '!**/node_modules/node-pre-gyp/lib/util/!(versioning.js|abi_crosswalk.json)', - '!**/node_modules/source-map-support/browser-source-map-support.js', - '!**/node_modules/json-schema/!(package.json|lib)' ], mac: { bundleVersion: '1.0',