2018-08-10 12:49:26 +02:00
|
|
|
// Copyright BigchainDB GmbH and BigchainDB contributors
|
|
|
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
|
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
2021-03-09 14:20:00 +01:00
|
|
|
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
|
|
|
|
|
2018-07-17 08:51:41 +02:00
|
|
|
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) {
|
2021-03-09 07:16:51 +01:00
|
|
|
const compiledAsset = new ConcatSource(main._value[0])
|
2018-07-17 08:51:41 +02:00
|
|
|
compiledAsset.add(vendor)
|
2021-03-09 07:16:51 +01:00
|
|
|
compiledAsset.add(main._value[1])
|
2018-07-17 08:51:41 +02:00
|
|
|
compilation.assets = {}
|
|
|
|
compilation.assets[this.base] = compiledAsset
|
|
|
|
} else if (main && mainMap) {
|
|
|
|
compilation.assets = {}
|
|
|
|
compilation.assets[this.base] = main
|
|
|
|
compilation.assets[`${this.base}.map`] = mainMap
|
|
|
|
}
|
2021-03-09 14:20:00 +01:00
|
|
|
|
2018-07-17 08:51:41 +02:00
|
|
|
callback()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|