Html-webpack-plugin: Use with `AgresssiveSplittingPlugin()` breaks because (?) `chunk.name = null;`

Created on 3 Oct 2016  路  21Comments  路  Source: jantimon/html-webpack-plugin

So I've been experimenting with a test branch on a starter repository using AgressiveSplittingPlugin(). You can see an example of AgressiveSplittingPlugin being used here in the webpack examples section.

I believe, looking at the code, that this fails because chunk.name is set to null (which basically renders your filterChunks() and other chunk/asset processing functions in the plugin useless).

https://github.com/webpack/webpack/blob/master/lib/optimize/AggressiveSplittingPlugin.js#L72
@sokra I was thinking: could we maybe change the chunk.name to [name]-split-[newChunk.newId]?

Otherwise, @jantimon is there a way to refactor that searching code, I played around a little bit, but wasn't able to determine a reliable way to fetch all assets that we're pulled out.

Most helpful comment

any news on this? we need this for amp/universal/http2 apps

All 21 comments

Hm don't know if there is much I can do here.. woukd it help if I would filter out all chunks without a name?

any news on this? we need this for amp/universal/http2 apps

Any news on this?

Webpack2 will introduce a new way to track entry points - I can't tell if this will fix it but it might

You can use the entrypoints property on the compilation. There is also a getFiles prop you can use to find assets for that ep. Entrypoint class will only contain references to initial chunk and entry chunks. So async chucks will not appear

Will this also work for the common chunks plugin?

Any news on this issue? I would love to use the AgressiveSplittinPlugin

Any news on this issue? I want to use the AgressiveSplittingPlugin

Same issue here... any update on this?

I'm waiting for it too

Saidly, but AggressiveSplittingPlugin doesn't work with HtmlWebpackPlugin. That means, it cann't be used in real production apps with long term caching.

I've been doing some digging into getting this plugin working with the AggressiveSplittingPlugin. The symptoms I was getting involved Conflict: Multiple assets emit to the same filename. Here's what was happening:

  • html-webpack-plugin compiles the html template, plus whatever compiler/templater (in my case jade) is required.
  • The combination of these were over the AggressiveSplitting split point so it split them up into multiple chunks
  • The chunks all got written to the same asset (whatever the template was called), throwing the error above.

This is probably what's going on in https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/323 too.

I think this is an issue with the html-webpack-plugin (and the extract-text one too) rather than with the AggressiveSplittingPlugin itself. Other plugins could feasibly create multiple chunks and they'd also trigger this problem. Basically the html-webpack-plugin needs to ensure that there's only one chunk by the time compilation has finished.

I've had a stab at doing that here: https://github.com/ortoo/html-webpack-plugin/commit/6d9996d8bd143d5026d63c78d91cd8d0c920c058 and it seems to do the job sufficiently for my use case though I feel there may be edge cases that it doesn't cover. I'm happy to put it into a PR if you think it's along the right lines.

@jamessharp I'm happy to contribute to that effort.. Can you please make that pr? I'd love to get some traction on this issue.

The extract-text-plugin and the html-webpack-plugin use a child compiler which inherits the AgressiveSplittingPlugin from your main compiler configuration.

As this problem will happen for every plugin with a child compiler in combination with the AgressiveSplittingPlugin so I guess it would be a great win to fix it inside the AgressiveSplittingPlugin.

I haven't looked to much in the source code of the plugin but a hook which would allow other plugins to to disable splitting or exclude chunks from splitting should work quite well.

PR created - #670

@jantimon - To circle back to this & after a brief conversation with @TheLarkInn on the topic. I was curious if it just doesn't make more sense to roll a purpose built plugin specifically for aggressive splitting as opposed to trying to wedge it in here.

The impression I got for reading through the comments is it would add a bunch of bloat you don't want in html-webpack-plugin nor do any of us really want to maintain a bunch of code for something we don't use.

We can add support here, we can build something in webpack-contrib & give you access to it, whatever works really. I think we are at the point where there is a big enough need that this needs to happen somewhere, curious what your preference is as to where.

This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.

@TheLarkInn i believe this topic took place prior to the splitChunks refactor, right? If so, I think this can be closed?

https://github.com/jantimon/html-webpack-plugin/pull/670 was closed because it seems to be fixed

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azat-io picture azat-io  路  4Comments

klinki picture klinki  路  3Comments

ruoyiqing picture ruoyiqing  路  3Comments

MatthewKosloski picture MatthewKosloski  路  3Comments

hp8wvvvgnj6asjm7 picture hp8wvvvgnj6asjm7  路  3Comments