In Electron, how to include only specific node_modules with electron-packager?

落爺英雄遲暮 提交于 2019-12-11 08:55:01

问题


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 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



来源:https://stackoverflow.com/questions/41953889/in-electron-how-to-include-only-specific-node-modules-with-electron-packager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!