-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
148 lines (141 loc) · 2.86 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const path = require('path');
const webpack = require('webpack');
//plugins
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const cssPlugin = new ExtractTextPlugin({
filename: '[name].[contenthash:8].css'
});
const PurifyCssPlugin = require('purifycss-webpack');
const glob = require('glob');
const Visualizer = require('webpack-visualizer-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BabiliPlugin = require('babili-webpack-plugin');
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
template: path.join(__dirname, 'index.html')
};
const prodConfig = {
entry: {
app: PATHS.app,
vendor: ['react', 'react-dom', 'redux', 'react-redux', 'redux-saga', 'babel-polyfill', 'chartist']
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash:8].js'
},
module: {
rules: [
{
test: /\.css$/,
use: cssPlugin.extract({
use: ['css-loader', 'postcss-loader'],
fallback: 'style-loader'
})
},
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['react', 'es2016', 'stage-2']
}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(PATHS.build),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new BabiliPlugin(),
/*new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
exclude: [PATHS.app]
}),*/
//new UglifyJsPlugin({exclude: [PATHS.app]}),
cssPlugin,
//new PurifyCssPlugin({
// paths: glob.sync(`${PATHS.app}/**/*.js`, {nodir: true }),
// minimize: false
//}),
new Visualizer(),
new HtmlWebpackPlugin()
]
};
const devConfig = {
entry: {
app: PATHS.app
},
output: {
path: PATHS.build,
filename: '[name].js'
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
options: {
emitWarning: true
}
},
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: true, importLoaders: 1 } },
'postcss-loader'
]
},
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['react', 'es2016', 'stage-2']
}
}
]
}
]
},
devServer: {
historyApiFallback: true,
stats: 'errors-only',
host: process.env.HOST,
port: process.env.PORT,
overlay: {
errors: true,
warnings: true
}
},
plugins: [
new HtmlWebpackPlugin({
template: PATHS.template
})
]
};
module.exports = (env) => {
console.log('env', env);
if (env === 'production') {
return prodConfig;
} else if (env === 'development') {
return devConfig;
}
};