Skip to content

Commit a896b69

Browse files
committed
Replace extract-text-webpack-plugin with mini-css-extract-plugin
According to the TL;DR of the comment below, mini-css-extract-plugin is replacing extract-text-webpack-plugin which will be deprecated. Since this does not have a built in optimizer for CSS, a separate plugin is used. However overriding the optimizer means that UglifyJS must be included manually (previously this was a transitive dependency of webpack which was used automatically in production mode) webpack-contrib/extract-text-webpack-plugin#749 (comment) This closes phoenixframework#2818
1 parent 52e3e8f commit a896b69

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

installer/templates/phx_assets/webpack/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
"babel-preset-env": "^1.6.1",
1616
"copy-webpack-plugin": "^4.5.0",
1717
"css-loader": "^0.28.10",
18-
"extract-text-webpack-plugin": "^4.0.0-beta.0",
18+
"mini-css-extract-plugin": "^0.4.0",
19+
"optimize-css-assets-webpack-plugin": "^4.0.0",
1920
"style-loader": "^0.20.2",
20-
"webpack": "4.0.0",
21+
"uglifyjs-webpack-plugin": "^1.2.4",
22+
"webpack": "4.4.0",
23+
2124
"webpack-cli": "^2.0.10"
2225
}
2326
}

installer/templates/phx_assets/webpack/webpack.config.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
const path = require('path');
2-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
4+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
35
const CopyWebpackPlugin = require('copy-webpack-plugin');
46

57
module.exports = (env, options) => ({
8+
optimization: {
9+
minimizer: [
10+
new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }),
11+
new OptimizeCSSAssetsPlugin({})
12+
]
13+
},
614
entry: './js/app.js',
715
output: {
816
filename: 'app.js',
@@ -19,17 +27,12 @@ module.exports = (env, options) => ({
1927
},
2028
{
2129
test: /\.css$/,
22-
use: ExtractTextPlugin.extract({
23-
fallback: 'style-loader',
24-
use: {
25-
loader: 'css-loader', options: { minimize: options.mode === 'production' }
26-
}
27-
})
30+
use: [MiniCssExtractPlugin.loader, 'css-loader']
2831
}
2932
]
3033
},
3134
plugins: [
32-
new ExtractTextPlugin('../css/app.css'),
35+
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
3336
new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
3437
]
3538
});

0 commit comments

Comments
 (0)