Sould SASS be installed as a 'dependency' or as a 'devDependency?
Asked Answered
G

2

14

Should sass be installed as a 'dependency' or as a 'devDependency'?

In the npm page says: " You can also add it to your project using npm install --save-dev sass."

But in the Install Sass page there is no information about this topic.

I have it like this and it works:

  "devDependencies": {
    "@parcel/transformer-sass": "^2.3.2",
    "parcel": "^2.3.2"
  },
  "dependencies": {
    "normalize.css": "^8.0.1",
    "sass": "^1.49.8"
}

But I wonder whether I should better have it as a devDependency.

Gumm answered 23/2, 2022 at 22:34 Comment(1)
F
10

I highly advise against installing npm packages like sass as a global dependency, this is particular important when you work collaboratively with others. The packages required for a project to run out of the box should be installed within the package itself. This ensures everything is contained within, and the project is capable of running standalone by a participant cloning the repo and running npm i.

As you mentioned, the official documentation for sass recommends installing it to a project via running npm install --save-dev sass. It should be noted that sass is a preprocessor which compiles .sass and .scss files to .css. It is therefore not required to run at production because when we compile our production build (such as with webpack), the associated .css files would have been generated. Thus, it is safe to download it as a dev dependency because we only need it during development.

Fraction answered 14/3, 2023 at 21:23 Comment(0)
J
0

I believe that it depends of your necessity and choice.

If you use the command npm install -g sass displayed in Sass's documentation, it will install sass globally in your machine and the sass package will not be added in your dependencies:

npm install -g sass

Although, if you run --save-dev it will be in your dependencies and always that someone clone your project and run npm install, the sass package will be installed (together with all the other dependencies).

Also I believe you can mix these commands and install globally and in your dependencies if you want: npm install -g --save-dev sass.

There are similar questions that can also help you:

What is the difference between --save and --save-dev?

Juliannajulianne answered 24/2, 2022 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.