Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.
This repository was archived by the owner on May 16, 2025. It is now read-only.

Plugin relies on chunk loading order #122

@DreierF

Description

@DreierF

The plugin still uses the "Webpack 3" way of loading asynchronous chunks in AGGRESSIVE_BUNDLE mode via the window.webpackJsonp function. This works as long as the main (or runtime chunk if using runtimeChunk: 'single') is loaded as the first script. This is however not the default in most configurations e.g. when using the default behavior of the HtmlWebpackPlugin.

As the order is non-deterministic or at least my change without touching the configuration you run into Uncaught ReferenceError: webpackJsonp is not defined when one if the async chunks is processed first.

The closure webpack plugin should instead use a mechanism similar to what Webpack 4+ does (Link) to load async chunks. Here window.webpackJsonp is initialized as (window.webpackJsonp = window.webpackJsonp || []).push(/* ... */);, which makes it independent from the script loading order as the runtime can pick up already loaded scripts from the array.

As a workaround I had to manually specify the loading order in HtmlWebpackPlugin like so:

new HtmlWebpackPlugin({
	chunksSortMode: function(a, b) {
		const partialOrderedChunks = [
			'runtime',
			'main'
		];
		return partialOrderedChunks.indexOf(b.names[0]) - partialOrderedChunks.indexOf(a.names[0]);
	}
}),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions