mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
const { ConcatSource } = require('webpack-sources')
|
|
|
|
module.exports = class AddVendorsPlugin {
|
|
constructor(base) {
|
|
this.base = base
|
|
}
|
|
|
|
apply(compiler) {
|
|
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}`]
|
|
|
|
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()
|
|
})
|
|
}
|
|
}
|