2018-11-26 15:55:09 +01:00
|
|
|
const { ConcatSource } = require('webpack-sources')
|
|
|
|
|
|
|
|
module.exports = class AddVendorsPlugin {
|
|
|
|
constructor(base) {
|
|
|
|
this.base = base
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
2019-11-15 00:00:10 +01:00
|
|
|
compiler.hooks.emit.tapAsync(
|
|
|
|
`AddVendorsPlugin ${this.base}`,
|
|
|
|
(compilation, callback) => {
|
|
|
|
const main = compilation.assets[`main.${this.base}`]
|
|
|
|
const mainMap = compilation.assets[`main.${this.base}.map`]
|
|
|
|
const vendor = compilation.assets[`vendors.${this.base}`]
|
2018-11-26 15:55:09 +01:00
|
|
|
|
2019-11-15 00:00:10 +01:00
|
|
|
if (main && vendor) {
|
|
|
|
const compiledAsset = new ConcatSource(main.children[0])
|
|
|
|
compiledAsset.add(vendor)
|
|
|
|
compiledAsset.add(main.children[1])
|
|
|
|
compilation.assets = {}
|
|
|
|
compilation.assets[this.base] = compiledAsset
|
|
|
|
} else if (main && mainMap) {
|
|
|
|
compilation.assets = {}
|
|
|
|
compilation.assets[this.base] = main
|
|
|
|
compilation.assets[`${this.base}.map`] = mainMap
|
|
|
|
}
|
|
|
|
callback()
|
2018-11-26 15:55:09 +01:00
|
|
|
}
|
2019-11-15 00:00:10 +01:00
|
|
|
)
|
2018-11-26 15:55:09 +01:00
|
|
|
}
|
|
|
|
}
|