1
1
'use strict' ;
2
+ let js = [ ] ;
3
+ let run = 0 ;
4
+
2
5
function HtmlWebpackMultiBuildPlugin ( options ) {
3
6
this . options = options ;
4
- this . js = [ ] ;
5
7
}
6
8
7
9
HtmlWebpackMultiBuildPlugin . prototype = {
8
10
apply : function ( compiler ) {
9
11
if ( compiler . hooks ) {
10
12
// webpack 4 support
11
13
compiler . hooks . compilation . tap ( 'HtmlWebpackMultiBuildPlugin' , compilation => {
12
- compilation . hooks . htmlWebpackPluginBeforeHtmlGeneration . tapAsync (
14
+ if ( compilation . hooks . htmlWebpackPluginBeforeHtmlGeneration ) {
15
+ compilation . hooks . htmlWebpackPluginBeforeHtmlGeneration . tapAsync (
13
16
'HtmlWebpackMultiBuildPlugin' ,
14
17
this . beforeHtmlGeneration . bind ( this ) ,
15
- ) ;
18
+ ) ;
19
+ } else {
20
+ var HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
21
+ var hooks = HtmlWebpackPlugin . getHooks ( compilation ) ;
22
+ hooks . beforeAssetTagGeneration . tapAsync (
23
+ 'HtmlWebpackMultiBuildPlugin' ,
24
+ this . beforeHtmlGeneration . bind ( this ) ,
25
+ ) ;
26
+ }
16
27
} ) ;
17
28
} else {
18
29
compiler . plugin ( 'compilation' , compilation => {
@@ -22,10 +33,14 @@ HtmlWebpackMultiBuildPlugin.prototype = {
22
33
} ,
23
34
24
35
beforeHtmlGeneration : function ( data , cb ) {
25
- this . js = this . js . concat ( data . assets . js ) ;
26
- data . assets . js = this . js ;
27
- data . plugin . options . modernScripts = this . js . filter ( ( value ) => value . indexOf ( 'legacy' ) === - 1 ) ;
28
- data . plugin . options . legacyScripts = this . js . filter ( ( value ) => value . indexOf ( 'legacy' ) > 0 ) ;
36
+ ++ run ;
37
+ js = js . concat ( data . assets . js ) ;
38
+ data . assets . js = js ;
39
+ if ( run === 2 ) {
40
+ data . plugin . options . modernScripts = js . filter ( ( value ) => value . indexOf ( 'legacy' ) === - 1 ) ;
41
+ data . plugin . options . legacyScripts = js . filter ( ( value ) => value . indexOf ( 'legacy' ) > 0 ) ;
42
+ }
43
+
29
44
cb ( null , data ) ;
30
45
} ,
31
46
} ;
0 commit comments