Skip to content

Commit ff72885

Browse files
mike-marcaccievilebottnawi
authored andcommitted
docs: add information about minimization (webpack-contrib#35)
1 parent 2899ed3 commit ff72885

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,47 @@ module.exports = {
6666
}
6767
```
6868

69+
### Minimizing For Production
70+
71+
While webpack 5 is likely to come with a CSS minimizer built-in, with webpack 4 you need to bring your own. To minify the output, use a plugin like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin). Setting `optimization.minimizer` overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
72+
73+
**webpack.config.js**
74+
75+
```js
76+
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
77+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
78+
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
79+
module.exports = {
80+
optimization: {
81+
minimizer: [
82+
new UglifyJsPlugin({
83+
cache: true,
84+
parallel: true,
85+
sourceMap: true // set to true if you want JS source maps
86+
}),
87+
new OptimizeCSSAssetsPlugin({})
88+
]
89+
},
90+
plugins: [
91+
new MiniCssExtractPlugin({
92+
filename: "[name].css",
93+
chunkFilename: "[id].css"
94+
})
95+
],
96+
module: {
97+
rules: [
98+
{
99+
test: /\.css$/,
100+
use: [
101+
MiniCssExtractPlugin.loader,
102+
"css-loader"
103+
]
104+
}
105+
]
106+
}
107+
}
108+
```
109+
69110
### Features
70111

71112
#### Using preloaded or inlined CSS

0 commit comments

Comments
 (0)