@@ -2,6 +2,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
22const { inlineSource } = require ( 'inline-source' ) ;
33const { getTagRegExp } = require ( 'inline-source/lib/utils' ) ;
44const htmlparser = require ( 'htmlparser2' ) ;
5+ const { Compilation } = require ( 'webpack' ) ;
56
67class InlineSourceWebpackPlugin {
78 constructor ( options = { } ) {
@@ -69,7 +70,7 @@ class InlineSourceWebpackPlugin {
6970 compilation . fileDependencies . add ( source . filepath ) ;
7071 } else {
7172 // Before Webpack 4
72- // fileDepenencies was an array
73+ // fileDependencies was an array
7374 compilation . fileDependencies . push ( source . filepath ) ;
7475 }
7576 }
@@ -124,7 +125,13 @@ class InlineSourceWebpackPlugin {
124125 */
125126 _deleteAsset ( compilation ) {
126127 if ( this . deleteAssets . length ) {
127- this . deleteAssets . forEach ( asset => delete compilation . assets [ asset . name ] ) ;
128+ if ( 'deleteAsset' in compilation ) {
129+ this . deleteAssets . forEach ( asset => {
130+ compilation . deleteAsset ( asset . name ) ;
131+ } ) ;
132+ } else {
133+ this . deleteAssets . forEach ( asset => delete compilation . assets [ asset . name ] ) ;
134+ }
128135 }
129136 this . deleteAssets = [ ] ;
130137 }
@@ -157,10 +164,19 @@ class InlineSourceWebpackPlugin {
157164 }
158165 } ) ;
159166 }
160- compiler . hooks . emit . tapAsync ( name , ( compilation , callback ) => {
161- this . _deleteAsset ( compilation ) ;
162- callback && callback ( ) ;
163- } ) ;
167+ if ( Compilation && Compilation . PROCESS_ASSETS_STAGE_SUMMARIZE ) {
168+ compiler . hooks . thisCompilation . tap ( name , compilation => {
169+ compilation . hooks . processAssets . tap (
170+ { name, stage : Compilation . PROCESS_ASSETS_STAGE_SUMMARIZE } ,
171+ ( ) => { this . _deleteAsset ( compilation ) ; }
172+ ) ;
173+ } ) ;
174+ } else {
175+ compiler . hooks . emit . tapAsync ( name , ( compilation , callback ) => {
176+ this . _deleteAsset ( compilation ) ;
177+ callback && callback ( ) ;
178+ } ) ;
179+ }
164180 } else {
165181 // webpack 2 or 3
166182 compiler . plugin ( 'compilation' , compilation => {
0 commit comments