-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
update readme with fix from #1939 #2114
Changes from all commits
80a10bf
d406724
24f3fcd
b3ce3f7
3dc41f0
8eaaad3
1baf645
df67823
32653a0
2b85cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,15 +398,14 @@ Following this rule often makes CSS preprocessors less useful, as features like | |
First, let’s install the command-line interface for Sass: | ||
|
||
``` | ||
npm install node-sass --save-dev | ||
npm install node-sass-chokidar --save-dev | ||
``` | ||
|
||
Then in `package.json`, add the following lines to `scripts`: | ||
|
||
```diff | ||
"scripts": { | ||
+ "build-css": "node-sass src/ -o src/", | ||
+ "watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive", | ||
+ "build-css": "node-sass-chokidar src/ -o src/", | ||
+ "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive", | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
|
@@ -430,8 +429,8 @@ Then we can change `start` and `build` scripts to include the CSS preprocessor c | |
|
||
```diff | ||
"scripts": { | ||
"build-css": "node-sass src/ -o src/", | ||
"watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive", | ||
"build-css": "node-sass-chokidar src/ -o src/", | ||
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we hide css compiled files in "npm start"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the initial terminal output? If so yes you can pass -q to build-css like so: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank to your reply. I mean that I want to use "node-sass-chokidar" but still can import .scss files. In some react apps built with webpack 2 as I did, we need just import .scss files, can run "npm start" in dev mode without compiling new css files. Therefore, can you improve it? example, build an entire css and hide it somewhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like @kellyrmilligan said, custom scss loaders are not supported at the moment.
anyways, perhaps you can convince the visionaries working on this to let you open a PR providing an entry point or env variable into the web-pack-config WITHOUT running eject? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelwayman : Thanks. That's exactly I want. P/S: I'm using VS, and config it to hide css files but it should be not the best method (import from a invisible file) |
||
- "start": "react-scripts start", | ||
- "build": "react-scripts build", | ||
+ "start-js": "react-scripts start", | ||
|
@@ -442,27 +441,19 @@ Then we can change `start` and `build` scripts to include the CSS preprocessor c | |
} | ||
``` | ||
|
||
Now running `npm start` and `npm run build` also builds Sass files. Note that `node-sass` seems to have an [issue recognizing newly created files on some systems](https://github.com/sass/node-sass/issues/1891) so you might need to restart the watcher when you create a file until it’s resolved. | ||
Now running `npm start` and `npm run build` also builds Sass files. | ||
|
||
**Performance Note** | ||
**Why `node-sass-chokidar`?** | ||
|
||
`node-sass --watch` has been reported to have *performance issues* in certain conditions when used in a virtual machine or with docker. If you are experiencing high CPU usage with node-sass you can alternatively try [node-sass-chokidar](https://www.npmjs.com/package/node-sass-chokidar) which uses a different file-watcher. Usage remains the same, simply replace `node-sass` with `node-sass-chokidar`: | ||
`node-sass` has been reported as having the following issues: | ||
|
||
``` | ||
npm uninstall node-sass --save-dev | ||
npm install node-sass-chokidar --save-dev | ||
``` | ||
- `node-sass --watch` has been reported to have *performance issues* in certain conditions when used in a virtual machine or with docker. | ||
|
||
And in your scripts: | ||
- Infinite styles compiling [#1939](https://github.com/facebookincubator/create-react-app/issues/1939) | ||
|
||
```diff | ||
"scripts": { | ||
- "build-css": "node-sass src/ -o src/", | ||
- "watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive" | ||
+ "build-css": "node-sass-chokidar src/ -o src/", | ||
+ "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive" | ||
} | ||
``` | ||
- `node-sass` has been reported as having issues with detecting new files in a directory [#1891](https://github.com/sass/node-sass/issues/1891) | ||
|
||
`node-sass-chokidar` is used here as it addresses these issues. | ||
|
||
## Adding Images, Fonts, and Files | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we build before we start watching? Does the watcher not compile everything when started in watch mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without the
build-css
inside ofwatch-css
there is no guarantee the latest stylesheets are being used when younpm run start
that is correct, the watcher does not compile everything when it first starts.
npm run start
you won't have ANY CSS files yetnpm run start
those changes won't show until you modify the stylesheet againThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to comment on this, I do like for example how the
babel
cli when started in watch mode does compile one time before the watch mode kicks in. something to think about and would simplify the scripts config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kellyrmilligan do you want to open an issue on node-sass-chokidar requesting this change? I will make the change this weekend if you do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make the files compile when started in watch mode, please add a flag to disable it.
It's very annoying that babel does it because you can't say "wait for first build before starting app".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelwayman: would it be helpful to include node_modules, like so:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajs139 we actually recently added a section about that. It gives advice more about importing without relative paths similar to the NODE PATH env variable fix. I always add my src directory as well.