1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Rewrite combine-asset-plugin using correct event (#3486)

* Speed up next build

* Remove comment

* Add comment

* Add comments
This commit is contained in:
Tim Neutkens 2017-12-22 10:25:35 +01:00 committed by GitHub
parent f2989c5739
commit c23046dc79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View file

@ -104,7 +104,8 @@
"webpack-dev-middleware": "1.12.0",
"webpack-hot-middleware": "2.19.1",
"write-file-webpack-plugin": "4.2.0",
"xss-filters": "1.2.7"
"xss-filters": "1.2.7",
"uglifyjs-webpack-plugin": "^1.1.1"
},
"devDependencies": {
"@taskr/babel": "1.1.0",
@ -134,7 +135,6 @@
"react-dom": "16.0.0",
"standard": "9.0.2",
"taskr": "1.1.0",
"uglifyjs-webpack-plugin": "^1.1.1",
"wd": "1.4.1"
},
"peerDependencies": {

View file

@ -11,26 +11,23 @@ export default class CombineAssetsPlugin {
apply (compiler) {
compiler.plugin('compilation', (compilation) => {
compilation.plugin('additional-chunk-assets', (chunks) => {
// This is triggered after uglify and other optimizers have ran.
compilation.plugin('after-optimize-chunk-assets', (chunks) => {
const concat = new ConcatSource()
this.input.forEach((name) => {
const asset = compilation.assets[name]
if (!asset) return
// We add each matched asset from this.input to a new bundle
concat.add(asset)
// We keep existing assets since that helps when analyzing the bundle
// The original assets are kept because they show up when analyzing the bundle using webpack-bundle-analyzer
// See https://github.com/zeit/next.js/tree/canary/examples/with-webpack-bundle-analyzer
})
compilation.additionalChunkAssets.push(this.output)
// Creates a new asset holding the concatted source
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))
})
})
}