@@ -47,57 +47,36 @@ module.exports = class HTMLGeneratorPlugin {
47
47
const pluginName = "html-generator-plugin" ;
48
48
49
49
compiler . hooks . thisCompilation . tap ( pluginName , ( compilation ) => {
50
- if ( compiler . webpack ) {
51
- const { RawSource } = compiler . webpack . sources ;
50
+ const { RawSource } = compiler . webpack . sources ;
52
51
53
- compilation . hooks . processAssets . tap (
54
- {
55
- name : pluginName ,
56
- stage : compiler . webpack . Compilation . PROCESS_ASSETS_STAGE_ADDITIONAL ,
57
- } ,
58
- ( ) => {
59
- const indexSource = new RawSource ( HTMLContentForIndex ) ;
60
- const testSource = new RawSource ( HTMLContentForTest ) ;
61
- const assets = compilation . getAssets ( ) ;
52
+ compilation . hooks . processAssets . tap (
53
+ {
54
+ name : pluginName ,
55
+ stage : compiler . webpack . Compilation . PROCESS_ASSETS_STAGE_ADDITIONAL ,
56
+ } ,
57
+ ( ) => {
58
+ const indexSource = new RawSource ( HTMLContentForIndex ) ;
59
+ const testSource = new RawSource ( HTMLContentForTest ) ;
60
+ const assets = compilation . getAssets ( ) ;
62
61
63
- compilation . emitAsset ( "index.html" , indexSource ) ;
64
- compilation . emitAsset ( "test.html" , testSource ) ;
62
+ compilation . emitAsset ( "index.html" , indexSource ) ;
63
+ compilation . emitAsset ( "test.html" , testSource ) ;
65
64
66
- for ( const asset of assets ) {
67
- const assetName = asset . name ;
65
+ for ( const asset of assets ) {
66
+ const assetName = asset . name ;
68
67
69
- if ( assetName !== "main.js" ) {
70
- const assetSource = new RawSource (
71
- HTMLContentForAssets ( assetName )
72
- ) ;
73
- compilation . emitAsset (
74
- assetName . replace ( ".js" , ".html" ) ,
75
- assetSource
76
- ) ;
77
- }
68
+ if ( assetName !== "main.js" ) {
69
+ const assetSource = new RawSource (
70
+ HTMLContentForAssets ( assetName )
71
+ ) ;
72
+ compilation . emitAsset (
73
+ assetName . replace ( ".js" , ".html" ) ,
74
+ assetSource
75
+ ) ;
78
76
}
79
77
}
80
- ) ;
81
- } else {
82
- compilation . hooks . additionalAssets . tap ( pluginName , ( ) => {
83
- compilation . emitAsset ( "index.html" , {
84
- source ( ) {
85
- return HTMLContentForIndex ;
86
- } ,
87
- size ( ) {
88
- return HTMLContentForIndex . length ;
89
- } ,
90
- } ) ;
91
- compilation . emitAsset ( "test.html" , {
92
- source ( ) {
93
- return HTMLContentForTest ;
94
- } ,
95
- size ( ) {
96
- return HTMLContentForTest . length ;
97
- } ,
98
- } ) ;
99
- } ) ;
100
- }
78
+ }
79
+ ) ;
101
80
} ) ;
102
81
}
103
82
} ;
0 commit comments