rsnext/server/build/plugins/combine-assets-plugin.js
Arunoda Susiripala 32af8294a7 Load the main JS bundle in production with async (#1485)
* Use a webpack plugin to combine assets.

* Add comments and make this releseable.

* Fix some typos.

* Fix some typos.
2017-03-24 13:21:34 +05:30

26 lines
692 B
JavaScript

// This plugin combines a set of assets into a single asset
// This should be only used with text assets,
// otherwise the result is unpredictable.
export default class CombineAssetsPlugin {
constructor ({ input, output }) {
this.input = input
this.output = output
}
apply (compiler) {
compiler.plugin('after-compile', (compilation, callback) => {
let newSource = ''
this.input.forEach((name) => {
newSource += `${compilation.assets[name].source()}\n`
delete compilation.assets[name]
})
compilation.assets[this.output] = {
source: () => newSource,
size: () => newSource.length
}
callback()
})
}
}