Using yarn, I have added few additional libraries ( let say jquery).
yarn add jquery
This will be added by default to dependencies block in package.json
but I want to change its location from dependencies to the devDependencies block.
What I currently do is:
yarn remove jquery
yarn add jquery -D
So I am looking for any command in yarn
or npm
which directly changes the library location from dependencies to the devDependencies block without uninstalling and reinstalling the same.
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 in this question.
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.
Choose your favorite combination out of the command line text editors: sed
, awk
, grep
, perl
or even python
. Or you could use a JSON editor like jq
.
You are right though - there should be a native command for this and perhaps we need to make a pull request to npm
/yarn
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With