1
- var path = require ( 'path' ) ;
2
- var fse = require ( 'fs-extra' ) ;
3
- var _ = require ( 'lodash' ) ;
4
- var mutexify = require ( 'mutexify' ) ;
1
+ const path = require ( 'path' ) ;
2
+ const fse = require ( 'fs-extra' ) ;
3
+ const _ = require ( 'lodash' ) ;
4
+ const mutexify = require ( 'mutexify' ) ;
5
5
6
- var lock = mutexify ( ) ;
6
+ const lock = mutexify ( ) ;
7
7
8
8
function ManifestPlugin ( opts ) {
9
9
this . opts = _ . assign ( {
@@ -16,40 +16,38 @@ function ManifestPlugin(opts) {
16
16
map : null ,
17
17
generate : null ,
18
18
sort : null ,
19
- serialize : function ( manifest ) {
20
- return JSON . stringify ( manifest , null , 2 ) ;
21
- } ,
19
+ serialize : manifest => JSON . stringify ( manifest , null , 2 ) ,
22
20
} , opts || { } ) ;
23
21
}
24
22
25
23
ManifestPlugin . prototype . getFileType = function ( str ) {
26
24
str = str . replace ( / \? .* / , '' ) ;
27
- var split = str . split ( '.' ) ;
28
- var ext = split . pop ( ) ;
25
+ const split = str . split ( '.' ) ;
26
+ let ext = split . pop ( ) ;
29
27
if ( this . opts . transformExtensions . test ( ext ) ) {
30
28
ext = split . pop ( ) + '.' + ext ;
31
29
}
32
30
return ext ;
33
31
} ;
34
32
35
33
ManifestPlugin . prototype . apply = function ( compiler ) {
36
- var seed = this . opts . seed || { } ;
37
- var moduleAssets = { } ;
34
+ const seed = this . opts . seed || { } ;
35
+ const moduleAssets = { } ;
38
36
39
- var moduleAsset = function ( module , file ) {
37
+ const moduleAsset = ( module , file ) => {
40
38
moduleAssets [ file ] = path . join (
41
39
path . dirname ( file ) ,
42
40
path . basename ( module . userRequest )
43
41
) ;
44
42
} ;
45
43
46
- var emit = function ( compilation , compileCallback ) {
47
- var publicPath = compilation . options . output . publicPath ;
48
- var stats = compilation . getStats ( ) . toJson ( ) ;
44
+ const emit = ( compilation , compileCallback ) => {
45
+ const publicPath = compilation . options . output . publicPath ;
46
+ const stats = compilation . getStats ( ) . toJson ( ) ;
49
47
50
- var files = compilation . chunks . reduce ( function ( files , chunk ) {
51
- return chunk . files . reduce ( function ( files , path ) {
52
- var name = chunk . name ? chunk . name : null ;
48
+ let files = compilation . chunks . reduce ( ( files , chunk ) => {
49
+ return chunk . files . reduce ( ( files , path ) => {
50
+ let name = chunk . name ? chunk . name : null ;
53
51
54
52
if ( name ) {
55
53
name = name + '.' + this . getFileType ( path ) ;
@@ -70,13 +68,13 @@ ManifestPlugin.prototype.apply = function(compiler) {
70
68
isAsset : false ,
71
69
isModuleAsset : false
72
70
} ) ;
73
- } . bind ( this ) , files ) ;
74
- } . bind ( this ) , [ ] ) ;
71
+ } , files ) ;
72
+ } , [ ] ) ;
75
73
76
74
// module assets don't show up in assetsByChunkName.
77
75
// we're getting them this way;
78
- files = stats . assets . reduce ( function ( files , asset ) {
79
- var name = moduleAssets [ asset . name ] ;
76
+ files = stats . assets . reduce ( ( files , asset ) => {
77
+ const name = moduleAssets [ asset . name ] ;
80
78
if ( name ) {
81
79
return files . concat ( {
82
80
path : asset . name ,
@@ -88,7 +86,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
88
86
} ) ;
89
87
}
90
88
91
- var isEntryAsset = asset . chunks . length > 0 ;
89
+ const isEntryAsset = asset . chunks . length > 0 ;
92
90
if ( isEntryAsset ) {
93
91
return files ;
94
92
}
@@ -103,28 +101,26 @@ ManifestPlugin.prototype.apply = function(compiler) {
103
101
} ) ;
104
102
} , files ) ;
105
103
106
- files = files . filter ( function ( file ) {
107
- // Don't add hot updates to manifest
108
- return file . path . indexOf ( 'hot-update' ) === - 1 ;
109
- } ) ;
104
+ // Don't add hot updates to manifest
105
+ files = files . filter ( file => ! file . path . includes ( 'hot-update' ) ) ;
110
106
111
107
// Append optional basepath onto all references.
112
108
// This allows output path to be reflected in the manifest.
113
109
if ( this . opts . basePath ) {
114
- files = files . map ( function ( file ) {
110
+ files = files . map ( file => {
115
111
file . name = this . opts . basePath + file . name ;
116
112
return file ;
117
- } . bind ( this ) ) ;
113
+ } ) ;
118
114
}
119
115
120
116
if ( publicPath ) {
121
117
// Similar to basePath but only affects the value (similar to how
122
118
// output.publicPath turns require('foo/bar') into '/public/foo/bar', see
123
119
// https://github.com/webpack/docs/wiki/configuration#outputpublicpath
124
- files = files . map ( function ( file ) {
120
+ files = files . map ( file => {
125
121
file . path = publicPath + file . path ;
126
122
return file ;
127
- } . bind ( this ) ) ;
123
+ } ) ;
128
124
}
129
125
130
126
files = files . map ( file => {
@@ -145,21 +141,21 @@ ManifestPlugin.prototype.apply = function(compiler) {
145
141
files = files . sort ( this . opts . sort ) ;
146
142
}
147
143
148
- var manifest ;
144
+ let manifest ;
149
145
if ( this . opts . generate ) {
150
146
manifest = this . opts . generate ( seed , files ) ;
151
147
} else {
152
- manifest = files . reduce ( function ( manifest , file ) {
148
+ manifest = files . reduce ( ( manifest , file ) => {
153
149
manifest [ file . name ] = file . path ;
154
150
return manifest ;
155
151
} , seed ) ;
156
152
}
157
153
158
- var output = this . opts . serialize ( manifest ) ;
154
+ const output = this . opts . serialize ( manifest ) ;
159
155
160
- var outputFolder = compilation . options . output . path ;
161
- var outputFile = path . resolve ( compilation . options . output . path , this . opts . fileName ) ;
162
- var outputName = path . relative ( outputFolder , outputFile ) ;
156
+ const outputFolder = compilation . options . output . path ;
157
+ const outputFile = path . resolve ( compilation . options . output . path , this . opts . fileName ) ;
158
+ const outputName = path . relative ( outputFolder , outputFile ) ;
163
159
164
160
compilation . assets [ outputName ] = {
165
161
source : function ( ) {
@@ -177,27 +173,34 @@ ManifestPlugin.prototype.apply = function(compiler) {
177
173
// NOTE: make sure webpack is not writing multiple manifests simultaneously
178
174
lock ( function ( release ) {
179
175
if ( compiler . hooks ) {
180
- compiler . hooks . afterEmit . tap ( 'ManifestPlugin' , function ( compilation ) {
176
+ compiler . hooks . afterEmit . tap ( 'ManifestPlugin' , compilation => {
181
177
release ( ) ;
182
178
} ) ;
179
+
180
+ compilation . hooks . webpackManifestPluginAfterEmit . call ( manifest , compileCallback ) ;
183
181
} else {
184
- compiler . plugin ( 'after-emit' , function ( compilation , cb ) {
182
+ compiler . plugin ( 'after-emit' , ( compilation , cb ) => {
185
183
release ( ) ;
186
184
cb ( ) ;
187
185
} ) ;
188
186
189
187
compilation . applyPluginsAsync ( 'webpack-manifest-plugin-after-emit' , manifest , compileCallback ) ;
190
188
}
191
189
} ) ;
192
- } . bind ( this ) ;
190
+ } ;
193
191
194
192
if ( compiler . hooks ) {
195
- compiler . hooks . compilation . tap ( 'ManifestPlugin' , function ( compilation ) {
193
+ compiler . hooks . compilation . tap ( 'ManifestPlugin' , compilation => {
194
+
195
+ const SyncWaterfallHook = require ( 'tapable' ) . SyncWaterfallHook ;
196
+
197
+ compilation . hooks . webpackManifestPluginAfterEmit = new SyncWaterfallHook ( [ 'manifest' , 'compileCallback' ] ) ;
198
+
196
199
compilation . hooks . moduleAsset . tap ( 'ManifestPlugin' , moduleAsset ) ;
197
200
} ) ;
198
201
compiler . hooks . emit . tap ( 'ManifestPlugin' , emit ) ;
199
202
} else {
200
- compiler . plugin ( 'compilation' , function ( compilation ) {
203
+ compiler . plugin ( 'compilation' , compilation => {
201
204
compilation . plugin ( 'module-asset' , moduleAsset ) ;
202
205
} ) ;
203
206
compiler . plugin ( 'emit' , emit ) ;
0 commit comments