本文介绍了为什么需要将Electron保存为开发人员依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据官方网站,保存电子文件的正确方法是:

As per the official website, the correct way to save electron files is:

npm install electron --save-dev

运行该应用程序实际上需要电子设备(实际上是require()),这与.那么,为什么即使是一个例外,我们为什么也要例外呢?

Electron is actually required for running the app (quite literally: require()) and this goes against the top voted answer here. So why do we make this exception, if this is even one?

推荐答案

require软件包与应将其视为依赖项还是devDependency(在npm意义上)无关.例如.许多项目使用webpack API(即const webpack = require('webpack')),但将其列为devDependency.

The fact that you require a package is irrelevant to whether it should be considered a dependency or a devDependency (in the npm sense). E.g. many projects use webpack API (i.e. const webpack = require('webpack')) but list it as a devDependency.

您链接到的帖子中也说明了原因:当您打包publish软件包时,如果使用者项目需要其他软件包才能使用您的软件包,那么这些软件包必须列为dependencies.

The reason is also explained in the post you link to: when you publish your package, if the consumer project needs other packages to use yours, then these must be listed as dependencies.

如果您的软件包仅将某些模块用于构建,测试或捆绑到dist文件中(即,消费者项目将使用的模块),则这些模块不应在dependencies中提及.我们仍将它们列在devDependencies中进行开发.

If your package uses some modules only for build, test, or bundles them into a dist file (i.e. what will be used by the consumer project), then those modules should not be mentioned in dependencies. We still list them in devDependencies for development.

现在,对于电子应用程序而言,您几乎没有机会将您的应用程序用作消费者项目的节点模块,因此上述约定并不是很重要.

Now in the case of an electron app, there is little chance you will consume your app as a node module of a consumer project, therefore the above convention is not really relevant.

此外,我们将electron包捆绑为内置输出的一部分.您的用户无需从npm获取electron来使用您构建的应用程序.因此,它与devDependency的定义非常匹配.

Furthermore, we fall in the case where the electron package is bundled as part of the built output. There is no need for your user to get electron from npm to use your built app. Therefore it matches well the definition of a devDependency.

话虽这么说,IIRC的一些电子包装商将您的dependencies捆绑到了内置的应用程序中,所以在填写此列表时您仍然需要一些严格的要求.

That being said, IIRC some electron packagers bundle your dependencies into the built app, so you still need some rigour in filling this list.

这篇关于为什么需要将Electron保存为开发人员依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:40