Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why react should usually be a prod dependency and not dev-dependency

Sorry if I'm missing some obvious thing, but I can't seem to understand why react (or react-dom) should be a dependency and not dev-dependency on most projects.. Usually the src is written in es6 and stored in /src or /client for example, and when someone want to build the project for prod he will create /build or /dist where the finalize bundle.js will seat (using webpack and such). from there (at prod) it simply a web server which serve regular js (the bundle) and html file.

Do I miss somthing?

I dont understand why will I want react on the prod (unless going for SSR of course)..

Thank you very much!

like image 429
Ron.B Avatar asked Feb 19 '18 08:02

Ron.B


People also ask

Should react be a dev dependency or dependency?

If you're building a React app, then react and react-dom would be dependencies . If you're using react-router for client-side routing, that would also be part of your dependencies . Any other packages like lodash or a design system library like Material UI ( @mui/material ) would also be dependencies .

What is difference between devDependencies and dependencies?

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

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 a react dependency?

November 29, 2021 4 min read. Dependency injection (DI) is a pattern where components necessary for your code to run are hot-swappable. This means that your dependencies are not hard-coded in your implementation and can change as your environment changes.


1 Answers

dependencies are required to run, devDependencies only to develop, e.g.: unit tests, Coffeescript to Javascript transpilation, minification, ...

React is a dependency because it is included in the final build.

In case of a React App, all your JSX is converted to a syntax similar to React.createElement and hence you would require your App to have React during run time as well. Similary methods like setState and lifecyle functions are all executed during run-time.

As a matter of fact react is a library that has exposed some methods and APIs to access and manipulate DOM.

Consider this similar to jquery or express where you add it in the production build because they are being used during run time.

When creating a react app, things like babel, webpack etc which are only used to create a bundle would be dev-dependencies as once the packaged bundle is generated it need not be generated during run time of application

like image 120
Shubham Khatri Avatar answered Sep 22 '22 13:09

Shubham Khatri