在Electron中,如何仅将特定的node_modules包含在electronic-packager中? [英] In Electron, how to include only specific node_modules with electron-packager?

查看:368
本文介绍了在Electron中,如何仅将特定的node_modules包含在electronic-packager中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打包我的电子应用,这需要mqtt和node-notifier模块。
所以我想做的是排除除它们之外的所有node_modules。

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

因此设置--ignore选项,例如:

So setting --ignore option like this:

--ignore='npm-debug|gulpfile\.js|\.vscode'

工作正常。但是除了排除mqtt和node-notifier以外的node_modules之外,我不知道如何制作正则表达式!

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

仅检查node_modules,/ ^((?! node_modules / mqtt)。)$ /是可行的,但是将它们组合成单个regex行,则不起作用。

Only checking node_modules, /^((?!node_modules/mqtt).)$/ is work, but combine them into single regex line, it's not working.

我知道我的正则表达式是错误的,但是我尝试了正则表达式字符和我的想象力的每种组合,每次尝试都失败了,并且在Google上找不到任何解决方案。

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.

这是 Regex测试网站,您可以看到我被困在哪里。

This is Regex Testing site, you can see where am I stucked.

任何建议将不胜感激。谢谢!

Any advice will be very appreciated. Thanks!

推荐答案

来自包装商 github页面


请注意不要包含 node_modules 您不希望进入最终应用程序。如果将它们放在 package.json devDependencies 部分,则默认情况下,与这些依赖项相关的模块都不会复制到应用程序捆绑包中。 (可以使用-no-prune 标志关闭此行为。)

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

来自电子包装商 API页面关于-修剪标志

From electron-packager API page about --prune flag


运行软件包管理器命令删除从输出的Electron应用程序中 package.json devDependencies 部分中指定的所有软件包。

Runs the package manager command to remove all of the packages specified in the devDependencies section of package.json from the outputted Electron app.

您应该能够简单地将除 mqtt 以外的所有软件包放在 devDependencies中并运行打包程序

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

这篇关于在Electron中,如何仅将特定的node_modules包含在electronic-packager中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆