在package.json中是否有任何简短的命令将一个模块从devDependencies移动到dependencies ?

我发现自己总是这样做:

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

有没有更简单的方法?


当前回答

I was trying to find an answer for this question for people that uses Yarn, but it hasn't a command for this matter yet. Although, I believe it is not essential anyway. Physically (in the Node modules folder) there are no difference between a dependency listed for production and the ones listed for development in your package.json, they'll go to the same place (node_modules). So, if you need to switch a dependency from devDependencies to dependecies you can go to your package.json and move manually with no need to run a new install or remove the dependency and then install it again with the dev flag. For me, it's not so great at all to manage the package.json manually, but Yarn is not as advanced as NPM in all functionalities, thus that's a thing to consider.

其他回答

是的!将一个模块从devDependencies移动到dependencies:

NPM install <module_name>——save-prod

从devDependencies转移到dependencies的简写(prod):

npm i <module_name> -P

如果你想做相反的事情(即将一个模块从dependencies移动到devDependencies),只需做:

npm install <module_name> --save-dev

或简写:

npm i <module_name> -D

如果您的项目还没有一个lockfile或shrinkwrap文件,您可以简单地移动package.json中的相应行。

(我不建议不使用锁文件)

对于Yarn,我手动将它们移动到包中。Json,然后运行yarn install。纱线锁文件没有得到更新,所以我认为这是好的。

纱:

将一个模块从devDependencies移动到dependencies:

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

将一个模块从dependencies移动到devDependencies:

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

正如评论中所说,该命令实际上删除了模块,并将其重新安装到新位置。