1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/build/plugins/combine-assets-plugin.js
Arunoda Susiripala bd80b78f5d Handle undefined assets when combining. (#1569)
It's possible for common.js to be empty in certain cases.
So, we need to handle it.
2017-03-30 16:35:53 +02:00

30 lines
748 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) => {
const asset = compilation.assets[name]
if (!asset) return
newSource += `${asset.source()}\n`
delete compilation.assets[name]
})
compilation.assets[this.output] = {
source: () => newSource,
size: () => newSource.length
}
callback()
})
}
}