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
Kevin Decker 53a2c5a7fc Combine source maps (#3178)
* Propagate source maps through combine assets step

* Use constant development build id

* Move combine assets step before uglify step

This ensures that uglify will catch these changes.

* Move dynamic chunks step before uglify step

This ensures that uglify will catch these changes.

* Use chunk templates for page and dynamic chunks

This is a little more in line with how webpack generates its bootstrap and should have better compatibility with other plugins and source map generation.

* Register combined source map with chunks

This ensures that a sourcemap is fully generated.

* Do not minimize combined map inputs
2017-10-30 15:57:35 +01:00

38 lines
1.1 KiB
JavaScript

import { ConcatSource } from 'webpack-sources'
// 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('compilation', (compilation) => {
compilation.plugin('additional-chunk-assets', (chunks) => {
const concat = new ConcatSource()
this.input.forEach((name) => {
const asset = compilation.assets[name]
if (!asset) return
concat.add(asset)
// We keep existing assets since that helps when analyzing the bundle
})
compilation.additionalChunkAssets.push(this.output)
compilation.assets[this.output] = concat
// Register the combined file as an output of the associated chunks
chunks.filter((chunk) => {
return chunk.files.reduce((prev, file) => prev || this.input.includes(file), false)
})
.forEach((chunk) => chunk.files.push(this.output))
})
})
}
}