You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
const {
|
|
info,
|
|
done
|
|
} = require('@vue/cli-shared-utils')
|
|
|
|
const updateComponents = require('./component')
|
|
const updateApis = require('./api')
|
|
|
|
class WebpackOptimizePlugin {
|
|
apply (compiler) {
|
|
let optimized = false
|
|
compiler.hooks.beforeCompile.tapPromise('WebpackOptimizePlugin', compilation => {
|
|
return new Promise((resolve, reject) => {
|
|
if (!optimized) {
|
|
updateComponents(new Set())
|
|
updateApis(new Set(), new Set())
|
|
}
|
|
resolve()
|
|
})
|
|
})
|
|
compiler.hooks.shouldEmit.tap('WebpackOptimizePlugin', compilation => {
|
|
return optimized
|
|
})
|
|
compiler.hooks.done.tapPromise('WebpackOptimizePlugin', compilation => {
|
|
return new Promise((resolve, reject) => {
|
|
if (!optimized) {
|
|
console.log()
|
|
info('Build optimizing...')
|
|
optimized = true
|
|
updateComponents(process.UNI_TAGS || new Set())
|
|
updateApis(process.UNI_APIS || new Set(), process.UNI_USER_APIS || new Set())
|
|
} else {
|
|
done('Build complete.')
|
|
process.exit(0)
|
|
}
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = WebpackOptimizePlugin
|
|
|