Is it possible to swap already installed packages from "dependencies" to "devDependencies" just by switching lines?

Asked

Viewed 119 times

0

Here’s an example of the file package.json, installed using the command npm install <nome> --save-dev:

{
"dependencies": {},
"devDependencies": {
"bootstrap": "^4.1.3",
"cross-env": "^5.2.0",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"node-sass": "^4.9.3"
}
}

If I just change manually like this, is something wrong? Outside of some convention, or can something else go wrong later?

(disregard the functionality of the packages, are only to exemplify):

{
"dependencies": {
"font-awesome": "^4.7.0",
},
"devDependencies": {
"bootstrap": "^4.1.3",
"cross-env": "^5.2.0",
"jquery": "^3.3.1",
"node-sass": "^4.9.3"
}
}

1 answer

2


Yes, you can move the packages of their dependencies and devDependencies editing the file package json. the way you described it. I would only take care to avoid any typos (e.g., you copied an unnecessary comma at the end of the line just before closing the keys to dependencies: "font-awesome": "^4.7.0",

To be more secure, I would use the traditional command:

npm install module --save-prod

To do the reverse (save as devDependency):

npm install module --save-dev
  • True, I forgot the comma. But as for your tip to use --save-Prod or --save-dev I had tried earlier and it does not make the change. I had to uninstall the package before and download it all again with the correct option.

  • Strange, I just tested here with the commands and it worked (it moved the package from one to the other). My node is in the version 8.10.0 and my npm in the version 5.6.0

  • It must be version then, when I did this, Node was in version 5.6 I think. Fabio, can I amend another pertinent question? If my project already has the folder node_modules in the .gitignore, what is the usability of this option --save-dev? In which case does it make a difference? Thank you.

  • the idea of --save-dev is that you (or any other developer working on the project) can install modules needed only for the development phase, on your local machine or IC environment (e.g., test modules, such as ava). These modules will not be installed in your production environment. Having them in package.json allows anyone, when cloning the project, just to run npm install to start developing

  • This part I understood. But what prevents me from raising them to production. Nothing correct? It serves only demonstrador from what I understand. Who really olha what goes into production and seleciona is just the .gitignore in the case of a user Git, That? Thank you so much for your time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.