How to install only “devDependencies” using npm

后端 未结 4 1540
耶瑟儿~
耶瑟儿~ 2021-01-30 05:07

I am trying to install ONLY the \"devDependencies\" listed in my package.json file. But none of the following commands work as I expect. All of the following commands install th

相关标签:
4条回答
  • 2021-01-30 05:17

    Check the NPM docs for install:

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

    The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV.

    Have you tried the following?

    npm install --only=dev
    
    0 讨论(0)
  • 2021-01-30 05:18
    npm i -D
    

    An optional short version.

    0 讨论(0)
  • 2021-01-30 05:21

    Running npm install, It will install all dependencies under devDependencies` or dependencies.

    For installing and save packages as dev dependencies in package.json, npm install package_name --save-dev or pass option -D

    For installing all packages under devDependencies, npm install --only=dev

    For installing and save packages as prod or only dependencies in package.json, npm install package_name --save-prod or pass option -P or npm install package_name

    For installing all packages under dependencies or Prod dependencies, set Environment variable NODE_ENV=production or pass it with the command NODE_ENV=production npm install or npm install --only=prod

    Instead of using install in npm command like npm install you can just use i like npm i, short of install.

    Reference

    0 讨论(0)
  • 2021-01-30 05:38
    npm install thePackageName --save-dev
    

    This works fine for me.

    0 讨论(0)
提交回复
热议问题