Skip to content

Commit 812330f

Browse files
authored
Add SASS support documentation facebook#1007
1 parent 79160b8 commit 812330f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/react-scripts/template/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
1818
- [Importing a Component](#importing-a-component)
1919
- [Adding a Stylesheet](#adding-a-stylesheet)
2020
- [Post-Processing CSS](#post-processing-css)
21+
- [Adding SASS Support](#adding-sass-support)
2122
- [Adding Images and Fonts](#adding-images-and-fonts)
2223
- [Using the `public` Folder](#using-the-public-folder)
2324
- [Adding Bootstrap](#adding-bootstrap)
@@ -301,6 +302,47 @@ becomes this:
301302

302303
There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
303304

305+
## Adding SASS Support
306+
307+
CSS preprocessors have become a vital part of build processes. Using a preprocesssor of your choice in a project bootstrapped using create-react-app, is fairly straightforward to setup, even without having to eject.
308+
309+
First, install preprocessor of your choice. SASS seems the most popular weapon of choice at the moment, so we'll use it as an example.
310+
311+
```
312+
npm install node-sass --save-dev
313+
```
314+
315+
Then in `package.json` just add the following lines to `scripts`, replacing file paths accordingly.
316+
```
317+
...
318+
"scripts": {
319+
...
320+
"build-css": "node-sass src/sass/base.scss src/index.css",
321+
"watch-css": "node-sass src/sass/base.scss src/index.css -w",
322+
...
323+
}
324+
...
325+
```
326+
327+
> Using a different preprocessor should be just a matter of replacing `build-css` and `watch-css` scripts to something that matches the preprocessor you're using.
328+
329+
Add these scripts to the main scripts, by pasting `npm run watch-css &` to `start` script and `npm run build-css &&` to `build`.
330+
331+
```
332+
...
333+
"scripts": {
334+
"start": "npm run watch-css & react-scripts start",
335+
"build": "npm run build-css && react-scripts build",
336+
"build-css": "node-sass src/sass/base.scss src/index.css",
337+
"watch-css": "node-sass src/sass/base.scss src/index.css -w",
338+
"test": "react-scripts test --env=jsdom",
339+
"eject": "react-scripts eject"
340+
}
341+
...
342+
```
343+
344+
Finally, you can use `npm start` or `npm run build` as usual.
345+
304346
## Adding Images and Fonts
305347

306348
With Webpack, using static assets like images and fonts works similarly to CSS.

0 commit comments

Comments
 (0)