Skip to content

Commit 71cbe59

Browse files
authored
Suggest sass instead of node-sass package (#10779)
1 parent 007a028 commit 71cbe59

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

docusaurus/docs/adding-a-sass-stylesheet.md

+23-18
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,36 @@ Generally, we recommend that you don’t reuse the same CSS classes across diffe
1010

1111
Following this rule often makes CSS preprocessors less useful, as features like mixins and nesting are replaced by component composition. You can, however, integrate a CSS preprocessor if you find it valuable.
1212

13-
To use Sass, first install `node-sass`:
13+
To use Sass, first install `sass`:
1414

1515
```sh
16-
$ npm install node-sass --save
17-
$ # or
18-
$ yarn add node-sass
16+
$ npm install sass
17+
# or
18+
$ yarn add sass
1919
```
2020

2121
Now you can rename `src/App.css` to `src/App.scss` and update `src/App.js` to import `src/App.scss`.
2222
This file and any other file will be automatically compiled if imported with the extension `.scss` or `.sass`.
2323

24-
To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions.
24+
To share variables between Sass files, you can use Sass's [`@use` rule](https://sass-lang.com/documentation/at-rules/use). For example, `src/App.scss` and other component style files could include `@use "./shared.scss";` with variable definitions.
2525

2626
This will allow you to do imports like
2727

2828
```scss
29-
@import 'styles/_colors.scss'; // assuming a styles directory under src/
30-
@import '~nprogress/nprogress'; // importing a css file from the nprogress node module
29+
@use 'styles/_colors.scss'; // assuming a styles directory under src/
30+
@use '~nprogress/nprogress'; // loading a css file from the nprogress node module
3131
```
3232

33-
> **Note:** You must prefix imports from `node_modules` with `~` as displayed above.
33+
> **Note:** You can prefix paths with `~`, as displayed above, to resolve modules from `node_modules`.
3434
35-
`node-sass` also supports the `SASS_PATH` variable.
35+
`sass` also supports the `SASS_PATH` variable.
3636

37-
To use imports relative to a path you specify, and from `node_modules` without adding the `~` prefix, you can add a [`.env` file](https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/adding-custom-environment-variables.md#adding-development-environment-variables-in-env) at the project root with the variable `SASS_PATH=node_modules:src`. To specify more directories you can add them to `SASS_PATH` separated by a `:` like `path1:path2:path3`.
37+
To use imports relative to a path you specify, you can add a [`.env` file](https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/adding-custom-environment-variables.md#adding-development-environment-variables-in-env) at the project root with the path specified in the `SASS_PATH` environment variable. To specify more directories you can add them to `SASS_PATH` separated by a `:` like `path1:path2:path3`.
3838

39-
If you set `SASS_PATH=node_modules:src`, this will allow you to do imports like
40-
```scss
41-
@import 'styles/colors'; // assuming a styles directory under src/, where _colors.scss partial file exists.
42-
@import 'nprogress/nprogress'; // importing a css file from the nprogress node module
43-
```
44-
45-
> **Note:** For windows operating system, use below syntax
39+
> **Note:** For the Windows operating system, separate your paths by semicolons.
4640
>
4741
> ```
48-
> SASS_PATH=./node_modules;./src
42+
> SASS_PATH=path1;path2;path3
4943
> ```
5044
5145
> **Tip:** You can opt into using this feature with [CSS modules](adding-a-css-modules-stylesheet.md) too!
@@ -61,3 +55,14 @@ If you set `SASS_PATH=node_modules:src`, this will allow you to do imports like
6155
> module.file_ext=.sass
6256
> module.file_ext=.scss
6357
> ```
58+
59+
> **Note:** LibSass and the packages built on top of it, including Node Sass, are [deprecated](https://sass-lang.com/blog/libsass-is-deprecated).
60+
> If you're a user of Node Sass, you can migrate to Dart Sass by replacing `node-sass` in your `package.json` file with `sass` or by running the following commands:
61+
>
62+
> ```sh
63+
> $ npm uninstall node-sass
64+
> $ npm install sass
65+
> # or
66+
> $ yarn remove node-sass
67+
> $ yarn add sass
68+
> ```

docusaurus/docs/adding-bootstrap.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ While you don’t have to use any specific library to integrate Bootstrap with R
88
Each project's respective documentation site has detailed instructions for installing and using them. Both depend on the Bootstrap css file so install that as well:
99

1010
```sh
11-
npm install --save bootstrap
11+
npm install bootstrap
1212
```
1313

1414
Alternatively you may use `yarn`:
@@ -33,19 +33,19 @@ Sometimes you might need to tweak the visual styles of Bootstrap (or equivalent
3333

3434
As of `react-scripts@2.0.0` you can import `.scss` files. This makes it possible to use a package's built-in Sass variables for global style preferences.
3535

36-
To enable `scss` in Create React App you will need to install `node-sass`.
36+
To enable `scss` in Create React App you will need to install `sass`.
3737

3838
```sh
39-
npm install --save node-sass
39+
npm install sass
4040
```
4141

4242
Alternatively you may use `yarn`:
4343

4444
```sh
45-
yarn add node-sass
45+
yarn add sass
4646
```
4747

48-
To customize Bootstrap, create a file called `src/custom.scss` (or similar) and import the Bootstrap source stylesheet. Add any overrides _before_ the imported file(s). You can reference [Bootstrap's documentation](https://getbootstrap.com/docs/4.1/getting-started/theming/#css-variables) for the names of the available variables.
48+
To customize Bootstrap, create a file called `src/custom.scss` (or similar) and import the Bootstrap source stylesheet. Add any overrides _before_ the imported file(s). You can reference [Bootstrap's documentation](https://getbootstrap.com/docs/4.6/getting-started/theming/#variable-defaults) for the names of the available variables.
4949

5050
```scss
5151
// Override default variables before the import
@@ -55,7 +55,7 @@ $body-bg: #000;
5555
@import '~bootstrap/scss/bootstrap.scss';
5656
```
5757

58-
> **Note:** You must prefix imports from `node_modules` with `~` as displayed above.
58+
> **Note:** You can prefix paths with `~`, as displayed above, to resolve modules from `node_modules`.
5959
6060
Finally, import the newly created `.scss` file instead of the default Bootstrap `.css` in the beginning of your `src/index.js` file, for example:
6161

packages/react-dev-utils/formatWebpackMessages.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ function formatMessage(message) {
7373
}
7474

7575
// Add helpful message for users trying to use Sass for the first time
76-
if (lines[1] && lines[1].match(/Cannot find module.+node-sass/)) {
77-
lines[1] = 'To import Sass files, you first need to install node-sass.\n';
76+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
77+
lines[1] = 'To import Sass files, you first need to install sass.\n';
7878
lines[1] +=
79-
'Run `npm install node-sass` or `yarn add node-sass` inside your workspace.';
79+
'Run `npm install sass` or `yarn add sass` inside your workspace.';
8080
}
8181

8282
message = lines.join('\n');

test/fixtures/webpack-message-formatting/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test('helps when users tries to use sass', async () => {
100100
expect(stdout).toBeFalsy();
101101
// TODO: Snapshots differ between Node 10/12 as the call stack log output has changed.
102102
expect(stderr).toContain(
103-
'To import Sass files, you first need to install node-sass.'
103+
'To import Sass files, you first need to install sass.'
104104
);
105105
});
106106

0 commit comments

Comments
 (0)