As per the official website, the correct way to save electron files is:
npm install electron --save-dev
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?
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.
devDependencies are those packages in the package. json file that you need only for project development purposes. Example- Babel, Webpack, etc. You require these packages to test and run your project on the localhost.
Development dependencies, or devDependencies are packages that are consumed by requiring them in files or run as binaries, during the development phase. These are packages that are only necessary during development and not necessary for the production build.
This approach considers that since your production app (aka the bundle you built with Webpack) can just run by itself, it means you have no production dependencies. Thus, all dependencies are devDependencies .
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.
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
.
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.
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.
That being said, IIRC some electron packagers bundle your dependencies
into the built app, so you still need some rigour in filling this list.
Cause those binary won't being used when you actually packaging into installer. Most of installer / packager for electron will build package with electron binaries, instead of using dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With