Skip to content

Commit 9223800

Browse files
kellyrmilliganromaindso
authored andcommitted
update readme with example of include path (facebook#2258)
* update readme with example of include path * Update README.md
1 parent f1ce474 commit 9223800

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/react-scripts/template/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,20 @@ Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`.
472472

473473
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.
474474

475+
To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`.
476+
477+
```
478+
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
479+
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
480+
```
481+
482+
This will allow you to do imports like
483+
484+
```scss
485+
@import 'styles/_colors.scss'; // assuming a styles directory under src/
486+
@import 'nprogress/nprogress'; // importing a css file from the nprogress node module
487+
```
488+
475489
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.
476490

477491
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:

0 commit comments

Comments
 (0)