Skip to content

Commit 437450f

Browse files
EugeneHlushkoevilebottnawi
authored andcommitted
docs(readme) Use mini-css-extract-plugin in examples. (#568)
* update(readme) Use mini-css-extract-plugin in examples. * update(readme) dont use variable for dev
1 parent 10a8161 commit 437450f

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

README.md

+20-25
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<p>Loads a Sass/SCSS file and compiles it to CSS.</p>
1919
</div>
2020

21-
Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-loader](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract it into a separate file.
21+
Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-loader](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract it into a separate file.
2222
Looking for the webpack 1 loader? Check out the [archive/webpack-1 branch](https://github.com/webpack-contrib/sass-loader/tree/archive/webpack-1).
2323

2424
<h2 align="center">Install</h2>
@@ -45,13 +45,11 @@ module.exports = {
4545
module: {
4646
rules: [{
4747
test: /\.scss$/,
48-
use: [{
49-
loader: "style-loader" // creates style nodes from JS strings
50-
}, {
51-
loader: "css-loader" // translates CSS into CommonJS
52-
}, {
53-
loader: "sass-loader" // compiles Sass to CSS
54-
}]
48+
use: [
49+
"style-loader", // creates style nodes from JS strings
50+
"css-loader", // translates CSS into CommonJS
51+
"sass-loader" // compiles Sass to CSS
52+
]
5553
}]
5654
}
5755
};
@@ -85,34 +83,31 @@ See [node-sass](https://github.com/andrew/node-sass) for all available Sass opti
8583

8684
### In production
8785

88-
Usually, it's recommended to extract the style sheets into a dedicated file in production using the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin). This way your styles are not dependent on JavaScript:
86+
Usually, it's recommended to extract the style sheets into a dedicated file in production using the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin). This way your styles are not dependent on JavaScript:
8987

9088
```js
91-
const ExtractTextPlugin = require("extract-text-webpack-plugin");
92-
93-
const extractSass = new ExtractTextPlugin({
94-
filename: "[name].[contenthash].css",
95-
disable: process.env.NODE_ENV === "development"
96-
});
89+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
9790

9891
module.exports = {
9992
...
10093
module: {
10194
rules: [{
10295
test: /\.scss$/,
103-
use: extractSass.extract({
104-
use: [{
105-
loader: "css-loader"
106-
}, {
107-
loader: "sass-loader"
108-
}],
109-
// use style-loader in development
110-
fallback: "style-loader"
111-
})
96+
use: [
97+
// fallback to style-loader in development
98+
process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader,
99+
"css-loader",
100+
"sass-loader"
101+
]
112102
}]
113103
},
114104
plugins: [
115-
extractSass
105+
new MiniCssExtractPlugin({
106+
// Options similar to the same options in webpackOptions.output
107+
// both options are optional
108+
filename: "[name].css",
109+
chunkFilename: "[id].css"
110+
})
116111
]
117112
};
118113
```

0 commit comments

Comments
 (0)