1
1
/**
2
- * This dependency plugin is a fork of:
2
+ * This dependency plugin is a fork of:
3
3
* chunk-manifest-webpack-plugin (https://github.com/soundcloud/chunk-manifest-webpack-plugin)
4
- *
4
+ *
5
5
* inline-chunk-manifest-html-webpack-plugin already enables inlining webpack's chunk manifest,
6
6
* and therefor has been extracted.
7
7
*/
@@ -22,15 +22,15 @@ class ChunkManifestPlugin {
22
22
const manifestVariable = this . manifestVariable ;
23
23
let chunkFilename ;
24
24
25
- compiler . plugin ( "this-compilation ", compilation => {
25
+ compiler . hooks . thisCompilation . tap ( "ChunkManifestPlugin ", compilation => {
26
26
const mainTemplate = compilation . mainTemplate ;
27
- mainTemplate . plugin ( "require-ensure ", function (
27
+ mainTemplate . hooks . requireEnsure . tap ( "ChunkManifestPlugin ", (
28
28
source ,
29
29
chunk ,
30
30
hash
31
31
/*, chunkIdVariableName */
32
- ) {
33
- chunkFilename = this . outputOptions . chunkFilename ;
32
+ ) => {
33
+ chunkFilename = compilation . outputOptions . chunkFilename ;
34
34
35
35
if ( chunkFilename ) {
36
36
const chunkManifest = [ chunk ] . reduce ( function registerChunk (
@@ -42,23 +42,29 @@ class ChunkManifestPlugin {
42
42
if ( c . hasRuntime ( ) ) {
43
43
manifest [ c . id ] = undefined ;
44
44
} else {
45
- const assetFilename = mainTemplate . applyPluginsWaterfall (
46
- "asset-path" ,
45
+ const assetFilename = mainTemplate . getAssetPath (
47
46
chunkFilename ,
48
47
{
49
- hash,
48
+ hash : hash ,
50
49
chunk : c
51
50
}
52
51
) ;
53
52
54
53
manifest [ c . id ] = assetFilename ;
55
54
}
56
55
57
- return c . chunks . reduce ( registerChunk , manifest ) ;
58
- } ,
59
- { } ) ;
56
+ const cGroups = Array . from ( c . groupsIterable ) ;
57
+ const cGroupsChildren = cGroups . map ( group => group . chunks ) ;
58
+ const unsortedChunks = cGroupsChildren . reduce (
59
+ ( chunksArray , childrens ) => chunksArray . concat ( childrens ) ,
60
+ [ ] ) ;
60
61
61
- this . outputOptions . chunkFilename = "__CHUNK_MANIFEST__" ;
62
+ const chunks = Array . from ( new Set ( unsortedChunks ) ) ;
63
+
64
+ return chunks . reduce ( registerChunk , manifest ) ;
65
+ } , { } ) ;
66
+
67
+ compilation . outputOptions . chunkFilename = "__CHUNK_MANIFEST__" ;
62
68
63
69
compilation . assets [ manifestFilename ] = new RawSource (
64
70
JSON . stringify ( chunkManifest )
@@ -69,16 +75,16 @@ class ChunkManifestPlugin {
69
75
} ) ;
70
76
} ) ;
71
77
72
- compiler . plugin ( "compilation ", compilation => {
78
+ compiler . hooks . compilation . tap ( "ChunkManifestPlugin ", compilation => {
73
79
const mainTemplate = compilation . mainTemplate ;
74
- mainTemplate . plugin ( "require-ensure ", function (
80
+ mainTemplate . hooks . requireEnsure . tap ( "ChunkManifestPlugin ", (
75
81
source ,
76
82
chunk ,
77
83
hash ,
78
84
chunkIdVariableName
79
- ) {
85
+ ) => {
80
86
if ( chunkFilename ) {
81
- this . outputOptions . chunkFilename = chunkFilename ;
87
+ compilation . outputOptions . chunkFilename = chunkFilename ;
82
88
}
83
89
84
90
const updatedSource = source . replace (
0 commit comments