forked from webpackmonitor/webpackmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.utils.js
58 lines (49 loc) · 1.47 KB
/
webpack.utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PurifyCSSPlugin = require('purifycss-webpack');
const webpack = require('webpack');
// EXTRACT ALL CSS INTO SEPERATE CSS FILE
// --------------------------------------
exports.extractCSS = ({ include, exclude } = {}) => {
const plugin = new ExtractTextPlugin({
filename: '[name].css'
});
return {
module: {
rules: [
{
test: /\.css$/,
include,
exclude,
use: plugin.extract({
use: 'css-loader',
fallback: 'style-loader'
})
}
]
},
plugins: [plugin]
};
};
// REMOVE ALL UNUSED CSS PROPERTIES
// --------------------------------
// **NOTE** must occur after ExtractTextPlugin (i.e. there needs to be some css)
// **NOTE** must also npm install purify-css
exports.purifyCSS = ({ paths }) => ({
// { Paths } can be a string or an array of paths, for the plugin to scan for css references
// For example: glob.sync(`${pathToAppDir}/**/*.js`, { nodir: true });
plugins: [new PurifyCSSPlugin({ paths })]
});
// EXTRACT ALL VENDOR CODE INTO NEW ASSET
// --------------------------------------
// Note: must include a separate 'vendor' entry point in webpack config
exports.extractVendorCode = () => ({
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
})
]
});
exports.uglifyJS = () => ({
plugins: [new webpack.optimize.UglifyJsPlugin()]
});