forked from dotkom/onlineweb4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.js
57 lines (50 loc) · 1.47 KB
/
webpack.production.config.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
// Breaks for some reason
/* eslint comma-dangle: ["error", {"functions":
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore",
}] */
const config = require('./webpack.config.js');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// Full source map
config.devtool = 'source-map';
// Set environment to production
// Some libraries use this to turn off some dev features
config.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}));
// We want to include CSS and JS seperately:
// Remove style loader
Object.keys(config.module.rules).forEach((key) => {
if ({}.hasOwnProperty.call(config.module.rules, key)) {
const loader = config.module.rules[key];
if ('.less'.match(loader.test)) {
loader.loader = ExtractTextPlugin.extract(
'css-loader?sourceMap!' +
'less-loader?sourceMap'
);
}
if ('.css'.match(loader.test)) {
loader.loader = ExtractTextPlugin.extract(
'css-loader?sourceMap'
);
}
}
});
// Add extract text plugin to extract css to .css files
config.plugins.push(new ExtractTextPlugin('[name]-[hash].css'));
// Uglify js
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
},
sourceMap: true,
comments: false,
}));
module.exports = config;