Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Electron need to be saved as a developer dependency?

Tags:

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?

like image 456
Prithvish Baidya Avatar asked Jun 11 '18 17:06

Prithvish Baidya


People also ask

Is electron a dev dependency?

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.

Why do we need dev dependencies?

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.

What is a developer dependency?

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.

Why is Webpack a dev dependency?

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 .


2 Answers

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.

like image 134
ghybs Avatar answered Nov 07 '22 07:11

ghybs


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.

like image 40
OJ Kwon Avatar answered Nov 07 '22 08:11

OJ Kwon