I'm writing an Angular Builder with some WebPack plugins and the issue I have is that my chunk after build including the self-execute sub-modules as following: ==> [[0, "runtime"]]]);
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["chunk-name"],{
0: (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__("chunk1-main-module");
}),
"chunk1-main-module": (function(module, exports, __webpack_require__) {
//... exports of main modules...
}),
"other-modules": (function(module, exports, __webpack_require__) {
//... exports of main module...
})
},[[0, "runtime"]]]);
In all scenarios I need to drop the runtime chunk from the deferred-modules list to look like that ==> [[0]]]);
Also the below code is able to make the chunk not self-executable, through selfExecute tag and if it's true it assign chunk.entryModule to undefined.
export class ChunkIdPlugin {
constructor(private selfExecute: boolean = false) { }
public apply = (compiler: Compiler): void =>
compiler.hooks.compilation.tap("ChunkIdPlugin", this.beforeChunkIds);
private beforeChunkIds = (compilation: compilation.Compilation): void =>
compilation.hooks.beforeChunkIds.tap("ChunkIdPlugin", this.iterateChunks);
private iterateChunks = (chunks: compilation.Chunk[]): void => {
const chunk = chunks.find(_ => _.name === 'main');
if (!chunk) return;
chunk.id = this.chunkId as any;
// If scenario demand that chunk doesn't self-execute assign the chunk.entryModule to undefined
(!this.selfExecute || chunk._groups.size < 1) && (chunk.entryModule = undefined);
// Loop through chunks and remove runtime chunk from compilation
for (let group of chunk._groups) {
const chunk = group.chunks.find(_ => _.name === 'runtime');
if (chunk) { chunk.remove(); break; }
}
}
}
After running this plugin on multiple chunks that require self-execute, WebPack runtime will have multiple chunks with id "0" which would lead to a conflict.
So my question is how to modify this plugin to make the deferred-modules to point to a specific submodule instead of "0" to avoid the conflict, as following: notice last line ==> },[["chunk1-main-module"]]]); instead of "0"
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["chunk-name"],{
0: (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__("chunk1-main-module");
}),
"chunk1-main-module": (function(module, exports, __webpack_require__) {
//... exports of main module...
})
},[["chunk1-main-module"]]]);