-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
132 lines (128 loc) · 3.25 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
const webpack = require('webpack')
const HappyPack = require('happypack')
const path = require('path')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const autoprefixer = require('autoprefixer')
const sourcePath = path.join(__dirname, './src')
const staticsPath = path.join(__dirname, './static')
module.exports = function () {
const nodeEnv = process.env.NODE_ENV ? 'production' : 'development'
const isProd = nodeEnv === 'production'
const plugins = [
new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(nodeEnv) } }),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true,
minChunks: Infinity
}),
new HappyPack({
verbose: false,
id: 'scss',
threads: 2,
loaders: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
}),
new HappyPack({
verbose: false,
id: 'eslint',
threads: 2,
loaders: ['eslint-loader']
}),
new HappyPack({
verbose: false,
id: 'js',
threads: 2,
loaders: ['babel-loader?cacheDirectory']
})
];
let methods = []
if (isProd) {
plugins.push(
new UglifyJSPlugin({
sourceMap: false,
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
output: { comments: false },
})
)
} else { plugins.push(new webpack.HotModuleReplacementPlugin()) }
return {
devtool: isProd ? 'source-map' : 'eval',
cache: true,
context: sourcePath,
entry: { js: './index.js' },
output: {
path: staticsPath,
publicPath: '/static/',
filename: 'bundle.js'
},
module: {
rules: [
...methods,
{
test: /\.js$/,
exclude: [/node_modules/],
use: ['happypack/loader?id=js', 'happypack/loader?id=eslint']
},
{
test: /\.scss$/,
exclude: [/node_modules/],
use: ['happypack/loader?id=scss']
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: ['file-loader?name=./fonts/[name].[ext]']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'url-loader?limit=10000',
'img-loader'
]
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.scss'],
modules: [path.resolve(__dirname, 'node_modules')]
},
plugins,
performance: isProd && {
maxAssetSize: 100000,
maxEntrypointSize: 600000,
hints: 'warning'
},
stats: { colors: { green: '\u001b[32m' } },
devServer: {
contentBase: './',
historyApiFallback: true,
port: 3000,
compress: isProd,
inline: !isProd,
hot: !isProd,
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
colors: { green: '\u001b[32m' }
}
}
}
}