问题
I'm try to packaging my electron app, and it requires mqtt and node-notifier module. So I want to do is exclude all node_modules except them.
Let's assume that I want to exclude these files from packaging:
- npm-debug
- gulpfile.js
- .vscode
So setting --ignore option like this:
--ignore='npm-debug|gulpfile\.js|\.vscode'
working fine. But additionally excluding node_modules except mqtt and node-notifier, I don't know how to make regex!
--ignore='npm-debug|gulpfile\.js|\.vscode|^((?!node_modules/mqtt).)$' // NOT WORKING
Only checking node_modules, /^((?!node_modules/mqtt).)$/ is work, but combine them into single regex line, it's not working.
I know my regex was wrong, but I tried every combination of regex characters and my imagination, every attempt was failed and couldn't found any solution on google.
This is Regex Testing site, you can see where am I stucked.
Any advice will be very appreciated. Thanks!
回答1:
From packager github page
Be careful not to include
node_modules
you don't want into your final app. If you put them in thedevDependencies
section ofpackage.json
, by default none of the modules related to those dependencies will be copied in the app bundles. (This behavior can be turned off with the--no-prune
flag.)
From electron-packager API page about --prune
flag
Runs the package manager command to remove all of the packages specified in the
devDependencies
section ofpackage.json
from the outputted Electron app.
You should be able to simply put all packages except mqtt
in devDependencies
and run packaging
来源:https://stackoverflow.com/questions/41953889/in-electron-how-to-include-only-specific-node-modules-with-electron-packager