Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack: Is package.json 'devDependencies' needed anymore?

I was playing with create-react-app and found out that it does put all packages under normal "dependencies". I built the app and found out the 'build' folder size was 2.66 MB.

Then I manually moved the packages not needed in production to "devDependencies" and built again, but the 'build' folder size was still 2.66 MB.

Is there some logic in the webpack.prod.js file, that knows what is needed even if all the packages are listed under "dependencies"?

If so, is there still some benefits using "devDependencies" in package.json?

like image 228
juwss Avatar asked Jul 28 '17 06:07

juwss


People also ask

Should webpack be in devDependencies?

The webpack and app dependencies can be placed in devDependencies . This scenario is also used if we are creating library packages, instead of servers. Others will install the project as a package, and require the pre-built files in their project.

Why do you need devDependencies?

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 the use of devDependencies in package json?

Dev Dependencies: In package. json file, there is an object called as dev Dependencies and it consists of all the packages that are used in the project in its development phase and not in the production or testing environment with its version number.

What is the difference between devDependencies and dependencies in package json?

"dependencies" : Packages required by your application in production. "devDependencies" : Packages that are only needed for local development and testing.

Should Webpack dependencies be listed as devdependencies or runtime dependencies?

I agree with @dschissler that everybody is doing this wrong. A browser app built by webpack has no runtime node dependencies, and thus all frontend dependencies should be listed as devDependencies.

What are the different types of dependencies in package JSON?

Among all types of dependencies in package.json, dependencies and devDependencies are the most frequently used, and the concepts are straightforward. Meanwhile, optionalDependencies and bundledDependencies are rarely used. The interesting and troublesome one is peerDependencies.

How to specify dependencies and devdependencies in a package?

Specifying dependencies and devDependencies in a package.json file. To specify the packages your project depends on, you must list them as "dependencies" or "devDependencies" in your package's package.json file. When you (or another user) run npm install, npm will download dependencies and devDependencies that are listed in package.json ...

How do I specify the packages my project depends on?

To specify the packages your project depends on, you must list them as "dependencies" or "devDependencies" in your package's package.json file. When you (or another user) run npm install, npm will download dependencies and devDependencies that are listed in package.json that meet the semantic version requirements listed for each.


1 Answers

When webpack builds your project it determines everything your project depends on, starting at the entry file, and then combines, uglifies and so on, and disregards everything else.

For example, if index.js is your entry file and it depends on moment.js, moment.js will be included in your build regardless if it's a dependency or devDependency.

The reason for this is npm distinguishes between dependencies and devDependencies, while webpack only distinguishes between that which is needed and that which is not.

If so, is there still some benefits using "devDependencies" in package.json?

I still use devDependencies, but solely as a means of ordering my package.json, but everything can safely be in dependencies when a tool such as webpack is used to build the production site/app

like image 112
Ettienne Avatar answered Oct 10 '22 05:10

Ettienne