-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
56 lines (52 loc) · 1.41 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
// @ts-check
const webpack = require('webpack');
const path = require('path');
// const PrepackWebpackPlugin = require('prepack-webpack-plugin').default;
// const configuration = { prepack: { sourceMaps: true } };
const NODE_ENV = process.env.NODE_ENV;
const config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './dist'),
libraryTarget: 'this',
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
},
],
},
devtool: 'source-map',
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
// new PrepackWebpackPlugin(configuration),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
],
};
if (NODE_ENV === 'development') {
config.watch = true;
config.output.filename = 'fuc.js';
} else if (NODE_ENV === 'production') {
config.output.filename = 'fuc.min.js';
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
// 最紧凑的输出
beautify: false,
// 删除所有的注释
comments: false,
compress: {
// 在UglifyJs删除没有用到的代码时不输出警告
warnings: false,
// 内嵌定义了但是只用到一次的变量
collapse_vars: true,
// 提取出出现多次但是没有定义成变量去引用的静态值
reduce_vars: true,
},
}),
);
}
module.exports = config;