Software hacker working in the industry since 2003. Currently loves: #Typescript and #Svelte and #golang. Founder of Chimera, the first makerspace in northern California.
For a lil more background, there is a difference between the behaviors of npm install --production, npm ci --only=prod, and --npm ci omit=dev:
npm install --production exhibits the same behavior that npm install does when you have a NODE_ENV=production environment variable set. So you can either set your NODE_ENV environment variable to production (recommended) or you could set this flag on npm install (or both to ensure that you get the behavior you want just in case something goes wrong with the environment variable!).
npm ci --only=prod and npm ci --omit=dev actually seem rather similar from what I could find. The only concern I would have with npm ci --only=prod is that it's not documented at all - only npm ci --include=prod is, but that could be because the documentation has changed since this article/comment was posted!
Anyways, npm ci --omit=dev prevents npm ci from installing devDependencies, however with this option the devDependencies are still included in the package-lock.json or npm-shrinkwrap.json files. This way, users can always manually install the devDependencies themselves later using npm ci --include=dev if they wish to develop the project. (See this documentation for further information.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What are your opinions comparing this method
npm install --only=prodwithnpm ci?I found that
npm ci --only=prodworks as well (see link)You're correct.
npm cialso installs dev dependencies.Adding
--only=prodor--productionwould not installdevDependenciesand just installdependencies.I'll update the article to show both options 👍
It's now recommended to use
--omit=devover--production😆 Good ole Node.js.For a lil more background, there is a difference between the behaviors of
npm install --production,npm ci --only=prod, and--npm ci omit=dev:npm install --productionexhibits the same behavior thatnpm installdoes when you have aNODE_ENV=productionenvironment variable set. So you can either set yourNODE_ENVenvironment variable to production (recommended) or you could set this flag onnpm install(or both to ensure that you get the behavior you want just in case something goes wrong with the environment variable!).npm ci --only=prodandnpm ci --omit=devactually seem rather similar from what I could find. The only concern I would have withnpm ci --only=prodis that it's not documented at all - onlynpm ci --include=prodis, but that could be because the documentation has changed since this article/comment was posted!Anyways,
npm ci --omit=devpreventsnpm cifrom installingdevDependencies, however with this option thedevDependenciesare still included in the package-lock.json or npm-shrinkwrap.json files. This way, users can always manually install thedevDependenciesthemselves later usingnpm ci --include=devif they wish to develop the project. (See this documentation for further information.