-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
121 lines (113 loc) · 4.34 KB
/
webpack.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const path = require('path');
const webpack = require('webpack');
const HtmlPlugin = require('html-webpack-plugin');
const TextPlugin = require('extract-text-webpack-plugin');
const {NODE_ENV} = process.env;
function getConfig(env) {
const isDevelopment = env === 'development';
return {
bail: !isDevelopment, // exit on error with status code 1
context: path.join(__dirname, 'app'),
entry: [
'babel-polyfill',
'./components/bootstrap/index.js',
],
output: {
filename: isDevelopment ? 'build.js' : 'build.min.js',
path: `${__dirname}/build`,
publicPath: '/',
pathinfo: isDevelopment,
},
resolve: {
extensions: ['.js'],
modules: [
path.join(__dirname, 'app'),
'node_modules',
],
},
devtool: 'source-map',
module: {
rules: [{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
presets: ['env'],
},
}, {
test: /\.css$/,
use: TextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true,
minimize: isDevelopment ? false : {
autoprefixer: false,
core: true,
convertValues: true,
discardComments: true,
discardEmpty: true,
mergeRules: true,
minifyGradients: true,
minifySelectors: true,
normalizeString: true,
normalizeUrl: true,
reduceBackgroundRepeat: true,
reducePositions: true,
reduceTransforms: true,
svgo: false,
styleCache: true,
reduceTimingFunctions: true,
reduceInitial: true,
orderedValues: true,
normalizeCharset: true,
minifyParams: true,
minifyFontValues: true,
mergeLonghand: true,
functionOptimiser: true,
filterOptimiser: true,
discardOverridden: true,
discardDuplicates: true,
colormin: true,
zindex: false,
},
},
},
{
loader: 'postcss-loader',
},
],
}),
}, {
test: /\.(gif|jpe?g|png)$/,
loader: 'url-loader?limit=1&name=images/[hash].[ext]',
}],
},
plugins: [
!isDevelopment && new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
new TextPlugin(isDevelopment ? 'styles.css' : 'styles.min.css'),
new HtmlPlugin({
template: 'layouts/template.html',
filename: 'index.html',
inject: true,
hash: !isDevelopment,
minify: !isDevelopment && {
html5: true,
collapseBooleanAttributes: true,
removeComments: true,
},
}),
].filter(Boolean),
watchOptions: {
aggregateTimeout: 100,
},
};
}
module.exports = (NODE_ENV === 'production')
? [getConfig('production'), getConfig('testing')]
: getConfig('development');