Is there a way of making “npm ci” install devDependencies, or “npm install” not update package-lock.json?

非 Y 不嫁゛ 提交于 2020-12-29 10:34:31

问题


I'm trying to put together documentation for new developers installing our codebase on their local development environments. I'd like to give them command(s) that:

  • Installs both devDependencies and dependencies based on the versions in package-lock.json
  • Doesn't update package-lock.json

"npm ci" does almost exactly what I want, but doesn't seem to install devDependencies. "npm install" does install devDependencies, but it sometimes modifies package-lock.json.

I could imagine something janky like "npm install && git checkout package-lock.json", but I feel like there must be a more idiomatic way of saying "give me a clean install of this project's dependencies for development?"


回答1:


npm ci does install both dependecies and dev dependencies. But if you use npm ci --production or if your NODE_ENV is set to production, then it avoids installing dev dependencies. Please check docs here.

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

NOTE: The --production flag has no particular meaning when adding a dependency to a project.




回答2:


Override NODE_ENV variable

When your NODE_ENV environment variable is set to production, using npm ci will not install devDependencies. But if you still want to install devDependencies

npm ci --also=dev

will do the trick ;)



来源:https://stackoverflow.com/questions/60065865/is-there-a-way-of-making-npm-ci-install-devdependencies-or-npm-install-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!