简体   繁体   English

生产 Electron 是否需要 node_modules/

[英]Does Production Electron need node_modules/

Been working on a Electron and React app for the past 4 months and we are getting close to releasing it.在过去的 4 个月里,我们一直在开发 Electron 和 React 应用程序,我们即将发布它。 This is my first production Electron app and I noticed the unpacked size was very large and the app.asar contained over 100mb of node_modules.这是我的第一个产品 Electron 应用程序,我注意到解压后的大小非常大,app.asar 包含超过 100mb 的 node_modules。

  • My colleague wrote the electron-builder config (probably just boilerplate code - Python dev) and it includes the react build/ and node_modules/ in the electron build.我的同事编写了 electron-builder 配置(可能只是样板代码 - Python dev),它在 electron 构建中包含 react build/ 和 node_modules/。 I understand React doesn't need any Node_modules once it is built because all of the code is bundled and a majority of these node_modules are for the react app.我知道 React 构建后不需要任何 Node_modules,因为所有代码都被捆绑在一起,并且这些 node_modules 中的大部分都用于 React 应用程序。
  • I would assume it would be the same after electron is built/compiled.我假设在构建/编译 electron 之后它会是一样的。 Or is it needed for nodejs deps?还是 nodejs 部门需要它? For the testing I did today I moved all of the react app's deps into devDeps so electron-builder doesn't include them.对于我今天所做的测试,我将所有 React 应用程序的 deps 都移到了 devDeps 中,因此 electron-builder 不包括它们。 It reduced the unpacked size by over 80% (over 500mb to under 150mb) because it included a bunch of ui stuff like icons that were tree shaken for the built react app.它将解压后的大小减少了 80% 以上(超过 500mb 到 150mb 以下),因为它包含了一堆 ui 的东西,比如为构建的 React 应用程序摇树的图标。 Inspecting the source tree for the built react app is under 2mb for node_modules.检查构建的 React 应用程序的源代码树对于 node_modules 小于 2mb。

TLDR: does my built electron app actually need node_modules included in the build (built for linux and armv7l)? TLDR:我构建的 electron 应用程序是否真的需要在构建中包含 node_modules(为 linux 和 armv7l 构建)? I know the react app does not after being built.我知道 React 应用程序在构建后不会。 And my temp work around has been moving my react deps to devDependencies so electron-builder ignores them.我的临时工作是将我的反应依赖转移到 devDependencies,所以 electron-builder 会忽略它们。 -- (I know this is not best practice because deploying the react app alone with a lot of services will only read the production dependencies - but shouldn't be an issue for our app's deployment) --(我知道这不是最佳实践,因为单独部署带有大量服务的 React 应用程序只会读取生产依赖项——但不应该成为我们应用程序部署的问题)

No, you should not need to include your node_modules in the electron build.不,您不需要在 electron 构建中包含您的node_modules Most of the required dependencies should be transpiled into the build folder.大多数必需的依赖项应该被转换到build文件夹中。

Docs here: https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules文档在这里: https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules

You should also be able to test this our pretty easily.您也应该能够很容易地对此进行测试。 Remove node_modules from the build target and test after running build.从构建目标中删除node_modules并在运行构建后进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM