mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
Update README.md
This commit is contained in:
@@ -87,10 +87,7 @@ Learn more about ES6 modules:
|
||||
|
||||
### Add a Stylesheet
|
||||
|
||||
This project setup uses [Webpack](https://webpack.github.io/) for handling all assets.
|
||||
Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript.
|
||||
|
||||
To express that a JavaScript file depends on a CSS file, you need to import it from the JavaScript file:
|
||||
This project setup uses [Webpack](https://webpack.github.io/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to import it from the JavaScript file:
|
||||
|
||||
#### `Button.css`
|
||||
|
||||
@@ -114,16 +111,11 @@ class Button extends Component {
|
||||
}
|
||||
```
|
||||
|
||||
**This is not required for React** but many people find this feature convenient.
|
||||
However be aware that this makes your code less portable to other build tools and environments than Webpack.
|
||||
**This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack.
|
||||
|
||||
In development, this allows your styles to be reloaded on the fly as you edit them.
|
||||
In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
|
||||
In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
|
||||
|
||||
You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b).
|
||||
|
||||
However **you are welcome to ignore it and put all your CSS in `src/index.css` if you prefer so.**
|
||||
It is imported from `src/index.js`, and you can always remove that import if you migrate to a different build tool.
|
||||
However **you are welcome to ignore it and put all your CSS in `src/index.css` if you prefer so.** It is imported from `src/index.js`, and you can always remove that import if you migrate to a different build tool.
|
||||
|
||||
### Post-Process CSS
|
||||
|
||||
@@ -162,8 +154,7 @@ There is currently no support for preprocessors such as Less, or for sharing var
|
||||
|
||||
With Webpack, using static assets like images and fonts works similarly to CSS.
|
||||
|
||||
You can `import` an image right in a JavaScript. This tells Webpack to include that image in the bundle.
|
||||
The *result* of the import is the image filename from the build output folder.
|
||||
You can `import` an image right in a JavaScript. This tells Webpack to include that image in the bundle. The *result* of the import is the image filename from the build output folder.
|
||||
|
||||
Here is an example:
|
||||
|
||||
@@ -191,11 +182,11 @@ This works in CSS too:
|
||||
|
||||
Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle.
|
||||
|
||||
If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets.
|
||||
If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module.
|
||||
|
||||
Please be advised that this is also a custom feature of Webpack.
|
||||
**It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).
|
||||
However it may not be portable to some other environments (for example, Node.js and Browserify).
|
||||
The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets.
|
||||
|
||||
Please be advised that this is also a custom feature of Webpack. **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images). However it may not be portable to some other environments, such as Node.js and Browserify.
|
||||
|
||||
If you’d prefer to add and reference static assets in a more traditional way outside the module system, please let us know [in this issue](https://github.com/facebookincubator/create-react-app/issues/28), and we will add support for this.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user