Move a module from devDependencies to dependencies in npm package.json

南楼画角 提交于 2020-01-11 15:16:12

问题


Is there any short command to move a module from devDependencies to dependencies in package.json?

I find myself always doing this:

npm uninstall <module_name> --save-dev 
npm install <module_name> --save

Is there a shorter approach to this?


回答1:


Yes! to move a module from devDependencies to dependencies:

npm install <module_name> --save-prod




回答2:


If you want to do the opposite (i.e. move a module from dependencies to devDependencies) just do:

npm install <module_name> --save-dev

or shorthand:

npm i <module_name> -D

shorthand to move from devDependencies to dependencies (prod):

npm i <module_name> -P



回答3:


In yarn:

move a module from devDependencies to dependencies:

yarn remove <module_name> --dev&yarn add <module_name> 

move a module from dependencies to devDependencies :

yarn remove <module_name>&yarn add <module_name> --dev

As said in the comments, the command actually deletes the module and reinstall it in the new place.




回答4:


If your project doesn't have a lockfile or a shrinkwrap file yet, you can simply move the corresponding line in your package.json.

(I'm not recommending not using lockfiles)




回答5:


The problem with using npm or yarn commands is that there is a chance that the version that is re-added is a different version than the one that is currently used. If this is what you want - both a move and an upgrade - then go ahead and use the accepted answer.

If not, simply manually edit your package.json to move the line from the devDependencies object to the dependencies object (creating it if necessary). You can go the other direction too.

The lock file doesn't hold any information about if things are prod or dev dependencies, so that doesn't need to be updated. You can do a npm/yarn install afterwards to fix up any flags in the lock files.



来源:https://stackoverflow.com/questions/46903002/move-a-module-from-devdependencies-to-dependencies-in-npm-package-json

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