-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdll.js
67 lines (55 loc) · 1.5 KB
/
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
const path = require('path')
const webpack = require('webpack')
const del = require('del')
const Messager = require('./messager')
const messager = new Messager()
module.exports = function (config) {
config = require('./core/common/common_config')(config, messager)
const { projectPath, system } = config
const { dll } = config.webpack || { }
if (!dll) {
messager.stop('dll config undefined')
return void 0
}
del.sync(`${projectPath}/dll/**/*`, { force: true })
const dllOptions = {
mode: 'production',
entry: dll,
output: {
filename: '[name].dll.js',
path: path.resolve(projectPath, 'dll'),
library: '_dll_[name]'
},
plugins: [
new webpack.DllPlugin({
name: '_dll_[name]',
path: path.join(projectPath, 'dll', '[name].manifest.json')
}),
new webpack.BannerPlugin({
banner: config.banner,
raw: true
})
],
context: system === 'mac' ? projectPath : projectPath.pathWinNorm()
}
const compiler = webpack(dllOptions)
compiler.run((error, stats) => {
if (error) {
messager.stop(`dll 打包错误: ${error.toString()}`)
} else {
const msg = stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
})
if (stats.compilation.errors.length > 0) {
messager.log(msg)
messager.stop(`dll 打包错误`)
} else {
messager.success('构建完成')
}
}
})
}