In Electron, how to include only specific node_mod

2019-07-25 13:54发布

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条回答
干净又极端
2楼-- · 2019-07-25 14:04

From packager github page

Be careful not to include node_modules you don't want into your final app. If you put them in the devDependencies section of package.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 of package.json from the outputted Electron app.

You should be able to simply put all packages except mqtt in devDependencies and run packaging

查看更多
登录 后发表回答