-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwebpack.config.dll.js
69 lines (62 loc) · 1.63 KB
/
webpack.config.dll.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
/* webpack --config webpack.config.dll.js --progress */
const path = require('path');
const lib = require('./config/lib.dependencies');
const webpack = require('webpack');
const isDebug = process.env.NODE_ENV === 'development';
const publicPath = './public/lib';
const outputPath = isDebug ? path.join(__dirname, `${publicPath}/debug`) : path.join(__dirname, `${publicPath}/min`);
console.log('isDebug', isDebug);
const plugin = [
new webpack.DllPlugin({
/**
* path
* 定义 manifest 文件生成的位置
* [name]的部分由entry的名字替换
*/
path: path.join(outputPath, 'manifest.json'),
/**
* name
* dll bundle 输出到那个全局变量上
* 和 output.library 一样即可。
*/
name: '[name]',
context: __dirname
})
];
if (!isDebug) {
plugin.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$', 'exports', 'require']
},
exclude: /\.min\.js$/,
compress: { warnings: false },
output: { comments: false }
}),
new webpack.ContextReplacementPlugin(
/moment[\/\\]locale$/,
/(en-gb|zh-cn).js/
)
);
}
module.exports = {
devtool: '#source-map',
context: path.resolve(__dirname),
entry: {
lib
},
output: {
path: outputPath,
filename: isDebug ? '[name].js' : '[name].[hash:9].js',
/**
* output.library
* 将会定义为 window.${output.library}
* 在这次的例子中,将会定义为`window.vendor_library`
*/
library: '[name]'
},
plugins: plugin
};