Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider moving react-scripts to devDependencies in the generated package #4342

Closed
nickserv opened this issue Apr 23, 2018 · 2 comments
Closed

Comments

@nickserv
Copy link
Contributor

nickserv commented Apr 23, 2018

It is a common convention for build tools to be in devDependencies instead of dependencies. I have noticed that create-react-app generates a package.json with only dependencies, and I think the react-scripts dependency counts as a build and testing tool which can be moved to devDependencies. If this hasn't already been discussed and it's possible for us to try it, I can start a PR on the template generator.

Note that even though react-scripts generates production code, npm still considers it a build tool that is not necessary in production environments because it does not produce code that relies on native Node bindings in production. Users can still safely install devDependencies in production environments if they can't build outside of their production environment, though I feel this is uncommon with GitHub Pages and Travis being so popular.

According to the npm docs for devDependencies:

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.

In this case, it's best to map these additional items in a devDependencies object.

These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param. See npm-config for more on the topic.

For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepare script to do this, and make the required package a devDependency.

@gaearon
Copy link
Contributor

gaearon commented Apr 23, 2018

It's been discussed numerous times before, see #2696.

TLDR: this solves issues for some users, and doesn't make any difference for other people. Those who don't like it can always move it to devDependencies themselves.

I don't think npm's advice is very relevant here. It is primarily concerning Node apps. CRA doesn't give you a Node app. From that perspective, all dependencies (including React) are "dev" dependencies because they're only necessary for the build: once you build the app, it has no deps at all. But putting react and react-dom in devDependencies will be just as confusing, and create those additional problems for some hosting providers. So instead we put them all in dependencies.

@gaearon gaearon closed this as completed Apr 23, 2018
@nickserv
Copy link
Contributor Author

Thanks, what changed my mind is knowing that the react-scripts package includes polyfills that are used in production.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants