Skip to content

Commit 3941db1

Browse files
TomTascheskipjack
authored andcommitted
add style-loader to tutorial "Code Splitting - CSS" (#1140)
docs(guides): improve "Code Splitting - CSS" guide
1 parent 5ebb244 commit 3941db1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

content/guides/code-splitting-css.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ contributors:
77
- johnstew
88
- simon04
99
- shinxi
10+
- tomtasche
1011
---
1112

1213
To bundle CSS files with webpack, import CSS into your JavaScript code like [any other module](/concepts/modules), and use the `css-loader` (which outputs the CSS as JS module), and optionally apply the `ExtractTextWebpackPlugin` (which extracts the bundled CSS and outputs CSS files).
@@ -21,12 +22,12 @@ import 'bootstrap/dist/css/bootstrap.css';
2122
```
2223

2324

24-
## Using `css-loader`
25+
## Using `css-loader` and `style-loader`
2526

26-
Install the [`css-loader`](/loaders/css-loader) loader:
27+
Install the [`css-loader`](/loaders/css-loader) and [`style-loader`](/loaders/style-loader):
2728

2829
``` bash
29-
npm install --save-dev css-loader
30+
npm install --save-dev css-loader style-loader
3031
```
3132

3233
Configure it in `webpack.config.js` as follows:
@@ -36,13 +37,13 @@ module.exports = {
3637
module: {
3738
rules: [{
3839
test: /\.css$/,
39-
use: 'css-loader'
40+
use: [ 'style-loader', 'css-loader' ]
4041
}]
4142
}
4243
}
4344
```
4445

45-
As a result, the CSS is bundled along with your JavaScript.
46+
As a result, the CSS is bundled along with your JavaScript and applied to the page via a `<style>`-tag injection after the initial load.
4647

4748
This has the disadvantage that you will not be able to utilize the browser's ability to load CSS asynchronously and parallel. Instead, your page will have to wait until your whole JavaScript bundle is loaded, to style itself.
4849

@@ -65,7 +66,7 @@ module.exports = {
6566
module: {
6667
rules: [{
6768
test: /\.css$/,
68-
- use: 'css-loader'
69+
- use: [ 'style-loader', 'css-loader' ]
6970
+ use: ExtractTextPlugin.extract({
7071
+ use: 'css-loader'
7172
+ })

0 commit comments

Comments
 (0)