Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details for using a css pre-processor. #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/guides/ReactComponents.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,51 @@ module.exports = {
}
```

### Adding a css pre-processor for sass

Install `node-sass-chokidar` and `npm-run-all`.

```sh
npm install node-sass-chokidar npm-run-all --save-dev
```

Update your `package.json` accordingly:

```json
"scripts": {
"start": "npm-run-all -p build-css start-js",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean watch-css instead of build-css?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a really long time ago. But i guess i mean build-css, because i created this repository using nwb and it has build-css and not watch-css

https://github.com/aviskarkc10/react-d3-donut/blob/master/package.json

I could very well be wrong.

"start-js": "nwb serve-react-demo",
"build": "npm-run-all build-css build-js",
"build-css": "node-sass-chokidar src/styles/ -o src/styles",
"build-js": "nwb build-react-component --copy-files",
"watch-css": "npm run build-css && node-sass-chokidar src/styles/ -o src/styles --watch --recursive"
}
```

The location `src/styles` is the location of your sass files. Remember to create a base sass file called `style.scss` where you import all the other sass. The other sass files should have filenames beginning with a `_`. For eg:

```
react-loading-button/
src/
styles/
_sass_file_one.scss
_sass_file_two.scss
styles.scss
index.js
```

The sass files will processed to a `styles.css` file which you will have to import to your component.

```js
import '../styles/style.css'
```

The css file will also be available on your build. Don't forget to add the css file to your `.gitignore`. For eg:

```
src/**/*.css
```

### Feature Toggles

Pass flags when running the build to toggle certain features off.
Expand Down