You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-scripts/template/README.md
+27-95Lines changed: 27 additions & 95 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ You can find the most recent version of this guide [here](https://github.com/fac
25
25
-[Code Splitting](#code-splitting)
26
26
-[Adding a Stylesheet](#adding-a-stylesheet)
27
27
-[Adding a CSS Modules stylesheet](#adding-a-css-modules-stylesheet)
28
+
-[Adding a Sass stylesheet](#adding-a-sass-stylesheet)
28
29
-[Post-Processing CSS](#post-processing-css)
29
-
-[Adding a CSS Preprocessor (Sass, Less etc.)](#adding-a-css-preprocessor-sass-less-etc)
30
30
-[Adding Images, Fonts, and Files](#adding-images-fonts-and-files)
31
31
-[Using the `public` Folder](#using-the-public-folder)
32
32
-[Changing the HTML](#changing-the-html)
@@ -567,6 +567,32 @@ No clashes from other `.error` class names
567
567
568
568
**This is an optional feature.** Regular html stylesheets and js imported stylesheets are fully supported. CSS Modules are only added when explicitly named as a css module stylesheet using the extension `.module.css`.
569
569
570
+
## Adding a Sass stylesheet
571
+
572
+
Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `<AcceptButton>` and `<RejectButton>` components, we recommend creating a `<Button>` component with its own `.Button` styles, that both `<AcceptButton>` and `<RejectButton>` can render (but [not inherit](https://facebook.github.io/react/docs/composition-vs-inheritance.html)).
573
+
574
+
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.
575
+
576
+
To use Sass, first install `node-sass`:
577
+
578
+
```bash
579
+
$ npm install node-sass --save
580
+
$ # or
581
+
$ yarn add node-sass
582
+
```
583
+
584
+
Now you can rename `src/App.css` to `src/App.scss` and update `src/App.js` to import `src/App.scss`.
585
+
This file and any other file will be automatically compiled if imported with the extension `.scss` or `.sass`.
586
+
587
+
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.
588
+
589
+
This will allow you to do imports like
590
+
591
+
```scss
592
+
@import'styles/_colors.scss'; // assuming a styles directory under src/
593
+
@import'nprogress/nprogress'; // importing a css file from the nprogress node module
594
+
```
595
+
570
596
## Post-Processing CSS
571
597
572
598
This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it.
@@ -600,100 +626,6 @@ becomes this:
600
626
601
627
If you need to disable autoprefixing for some reason, [follow this section](https://github.com/postcss/autoprefixer#disabling).
602
628
603
-
## Adding a CSS Preprocessor (Sass, Less etc.)
604
-
605
-
Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `<AcceptButton>` and `<RejectButton>` components, we recommend creating a `<Button>` component with its own `.Button` styles, that both `<AcceptButton>` and `<RejectButton>` can render (but [not inherit](https://facebook.github.io/react/docs/composition-vs-inheritance.html)).
606
-
607
-
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. In this walkthrough, we will be using Sass, but you can also use Less, or another alternative.
608
-
609
-
First, let’s install the command-line interface for Sass:
610
-
611
-
```sh
612
-
npm install --save node-sass-chokidar
613
-
```
614
-
615
-
Alternatively you may use `yarn`:
616
-
617
-
```sh
618
-
yarn add node-sass-chokidar
619
-
```
620
-
621
-
Then in `package.json`, add the following lines to `scripts`:
> Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation.
633
-
634
-
Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`. The watcher will find every Sass file in `src` subdirectories, and create a corresponding CSS file next to it, in our case overwriting `src/App.css`. Since `src/App.js` still imports `src/App.css`, the styles become a part of your application. You can now edit `src/App.scss`, and `src/App.css` will be regenerated.
635
-
636
-
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.
637
-
638
-
To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`.
@import'styles/_colors.scss'; // assuming a styles directory under src/
649
-
@import'nprogress/nprogress'; // importing a css file from the nprogress node module
650
-
```
651
-
652
-
At this point you might want to remove all CSS files from the source control, and add `src/**/*.css` to your `.gitignore` file. It is generally a good practice to keep the build products outside of the source control.
653
-
654
-
As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this:
655
-
656
-
```sh
657
-
npm install --save npm-run-all
658
-
```
659
-
660
-
Alternatively you may use `yarn`:
661
-
662
-
```sh
663
-
yarn add npm-run-all
664
-
```
665
-
666
-
Then we can change `start` and `build` scripts to include the CSS preprocessor commands:
0 commit comments