問題描述
根據官網,電子文件的正確保存方法是:
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.
原因在你鏈接到的帖子中也有解釋:當你發布
你的包時,如果消費者項目需要其他包來使用你的包,那么這些必須列為 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 需要保存為開發者依賴?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!