Skip to content

Commit 323cd74

Browse files
committed
Move adding a sass stylesheet to its own file
1 parent 4249b3f commit 323cd74

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
id: adding-a-sass-stylesheet
3+
title: Adding a Sass Stylesheet
4+
---
5+
6+
> Note: this feature is available with `[email protected]` and higher.
7+
8+
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)).
9+
10+
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.
11+
12+
To use Sass, first install `node-sass`:
13+
14+
```bash
15+
$ npm install node-sass --save
16+
$ # or
17+
$ yarn add node-sass
18+
```
19+
20+
Now you can rename `src/App.css` to `src/App.scss` and update `src/App.js` to import `src/App.scss`.
21+
This file and any other file will be automatically compiled if imported with the extension `.scss` or `.sass`.
22+
23+
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+
25+
This will allow you to do imports like
26+
27+
```scss
28+
@import 'styles/_colors.scss'; // assuming a styles directory under src/
29+
@import '~nprogress/nprogress'; // importing a css file from the nprogress node module
30+
```
31+
32+
> **Tip:** You can opt into using this feature with [CSS modules](#adding-a-css-modules-stylesheet) too!
33+
34+
> **Note:** You must prefix imports from `node_modules` with `~` as displayed above.

docusaurus/docs/user-guide.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
1111

1212
## Table of Contents
1313

14-
- [Adding a Sass Stylesheet](#adding-a-sass-stylesheet)
1514
- [Post-Processing CSS](#post-processing-css)
1615
- [Adding Images, Fonts, and Files](#adding-images-fonts-and-files)
1716
- [Adding SVGs](#adding-svgs)
@@ -45,38 +44,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
4544
- [Advanced Configuration](#advanced-configuration)
4645
- [Alternatives to Ejecting](#alternatives-to-ejecting)
4746

48-
## Adding a Sass Stylesheet
49-
50-
> Note: this feature is available with `[email protected]` and higher.
51-
52-
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)).
53-
54-
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.
55-
56-
To use Sass, first install `node-sass`:
57-
58-
```bash
59-
$ npm install node-sass --save
60-
$ # or
61-
$ yarn add node-sass
62-
```
63-
64-
Now you can rename `src/App.css` to `src/App.scss` and update `src/App.js` to import `src/App.scss`.
65-
This file and any other file will be automatically compiled if imported with the extension `.scss` or `.sass`.
66-
67-
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.
68-
69-
This will allow you to do imports like
70-
71-
```scss
72-
@import 'styles/_colors.scss'; // assuming a styles directory under src/
73-
@import '~nprogress/nprogress'; // importing a css file from the nprogress node module
74-
```
75-
76-
> **Tip:** You can opt into using this feature with [CSS modules](#adding-a-css-modules-stylesheet) too!
77-
78-
> **Note:** You must prefix imports from `node_modules` with `~` as displayed above.
79-
8047
## Post-Processing CSS
8148

8249
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.

docusaurus/website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"importing-a-component",
2323
"code-splitting",
2424
"adding-a-stylesheet",
25-
"adding-a-css-modules-stylesheet"
25+
"adding-a-css-modules-stylesheet",
26+
"adding-a-sass-stylesheet"
2627
],
2728
"Testing": ["running-tests", "debugging-tests"],
2829
"Deployment": ["publishing-components-to-npm", "deployment"],

0 commit comments

Comments
 (0)