This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathservice.js
140 lines (121 loc) · 4.57 KB
/
service.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
const {
log,
isInstallOf,
forEachObj,
isFunctionAndCall
} = require('./src/helper')
const Dll = require('./src/dll.js')
module.exports = (api, options) => {
const webpack = require('webpack')
const dllConfig = (options.pluginOptions && options.pluginOptions.dll) || {}
const dll = new Dll(api.resolveWebpackConfig(), dllConfig)
api.chainWebpack(config => {
if (!dll.isOpen || dll.isCommand === true) return
const referenceArgs = dll.resolveDllReferenceArgs()
config.when(referenceArgs.length !== 0, config => {
// add DllReferencePlugins
referenceArgs.forEach(args => {
config
.plugin(`dll-reference-${args.manifest.name}`)
.use(webpack.DllReferencePlugin, [args])
})
// auto inject
if (dll.inject) {
config
.plugin('dll-add-asset-html')
.use(
require('add-asset-html-webpack-plugin'),
dll.resolveAddAssetHtmlArgs()
)
if(config.plugins.has('copy')) {
// add copy agrs
config.plugin('copy').tap(args => {
args[0][0].ignore.push(dll.outputDir + '/**')
args[0].push({
from: dll.outputPath,
toType: 'dir',
ignore: ['*.js', '*.css', '*.manifest.json']
})
return args
})
}
}
})
})
api.registerCommand(
'dll',
{
description: 'build dll',
usage: 'vue-cli-service dll',
options: {}
},
async function(args) {
dll.callCommand()
// entry parameter can not be empty
if (!dll.validateEntry()) {
throw Error('"entry" parameter no found, more config url:')
}
const FileNameCachePlugin = require('./src/fileNameCachePlugin')
api.chainWebpack(config => {
config
.plugin('dll')
.use(webpack.DllPlugin, dll.resolveDllArgs())
.end()
.plugin('file-list-plugin')
.use(FileNameCachePlugin)
config.optimization.delete('splitChunks')
config.optimization.delete('runtimeChunk')
config.devtool(false)
// set output
forEachObj(dll.resolveOutput(), (fnName, value) => {
isFunctionAndCall(
config.output[fnName],
config.output,
value
)
})
})
let webpackConfig = api.resolveWebpackConfig()
let { VueLoaderPlugin } = require('vue-loader')
let DefinePlugin = require('webpack/lib/DefinePlugin')
let FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
let NamedChunksPlugin = require('webpack/lib/NamedChunksPlugin')
let MiniCssExtreactPlugin = require('mini-css-extract-plugin')
let OptimizeCssnanoPlugin = require('@intervolga/optimize-cssnano-plugin')
let fs = require('fs-extra')
// filter plugins
webpackConfig.plugins = webpackConfig.plugins.filter(i =>
isInstallOf(
i,
VueLoaderPlugin,
DefinePlugin,
FriendlyErrorsWebpackPlugin,
NamedChunksPlugin,
MiniCssExtreactPlugin,
webpack.DllPlugin,
FileNameCachePlugin,
OptimizeCssnanoPlugin
)
)
// reset entry
webpackConfig.entry = dll.resolveEntry()
// remove dir
fs.remove(dll.outputPath)
log('Starting build dll...')
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
return reject(err)
} else if (stats.hasErrors()) {
return reject(new Error('Build failed with errors.'))
}
log('Build complete.')
resolve()
})
})
}
)
}
module.exports.defaultModes = {
dll: 'production'
}