@@ -1232,6 +1232,74 @@ describe('HtmlWebpackPlugin', () => {
1232
1232
null , done , false , false ) ;
1233
1233
} ) ;
1234
1234
1235
+ it ( 'allows events to remove an attribute by setting it to null' , done => {
1236
+ const examplePlugin = {
1237
+ apply : function ( compiler ) {
1238
+ compiler . hooks . compilation . tap ( 'HtmlWebpackPlugin' , compilation => {
1239
+ HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTags . tapAsync ( 'HtmlWebpackPluginTest' , ( pluginArgs , callback ) => {
1240
+ pluginArgs . assetTags . scripts = pluginArgs . assetTags . scripts . map ( tag => {
1241
+ if ( tag . tagName === 'script' ) {
1242
+ tag . attributes . async = null ;
1243
+ }
1244
+ return tag ;
1245
+ } ) ;
1246
+ callback ( null , pluginArgs ) ;
1247
+ } ) ;
1248
+ } ) ;
1249
+ }
1250
+ } ;
1251
+ testHtmlPlugin ( {
1252
+ mode : 'production' ,
1253
+ entry : {
1254
+ app : path . join ( __dirname , 'fixtures/index.js' )
1255
+ } ,
1256
+ output : {
1257
+ path : OUTPUT_DIR ,
1258
+ filename : '[name]_bundle.js'
1259
+ } ,
1260
+ plugins : [
1261
+ new HtmlWebpackPlugin ( ) ,
1262
+ examplePlugin
1263
+ ]
1264
+ } ,
1265
+ [ / < s c r i p t d e f e r = " d e f e r " s r c = " a p p _ b u n d l e .j s " > < \/ s c r i p t > [ \s ] * < \/ h e a d > / ] ,
1266
+ null , done , false , false ) ;
1267
+ } ) ;
1268
+
1269
+ it ( 'allows events to remove an attribute by setting it to undefined' , done => {
1270
+ const examplePlugin = {
1271
+ apply : function ( compiler ) {
1272
+ compiler . hooks . compilation . tap ( 'HtmlWebpackPlugin' , compilation => {
1273
+ HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTags . tapAsync ( 'HtmlWebpackPluginTest' , ( pluginArgs , callback ) => {
1274
+ pluginArgs . assetTags . scripts = pluginArgs . assetTags . scripts . map ( tag => {
1275
+ if ( tag . tagName === 'script' ) {
1276
+ tag . attributes . async = undefined ;
1277
+ }
1278
+ return tag ;
1279
+ } ) ;
1280
+ callback ( null , pluginArgs ) ;
1281
+ } ) ;
1282
+ } ) ;
1283
+ }
1284
+ } ;
1285
+ testHtmlPlugin ( {
1286
+ mode : 'production' ,
1287
+ entry : {
1288
+ app : path . join ( __dirname , 'fixtures/index.js' )
1289
+ } ,
1290
+ output : {
1291
+ path : OUTPUT_DIR ,
1292
+ filename : '[name]_bundle.js'
1293
+ } ,
1294
+ plugins : [
1295
+ new HtmlWebpackPlugin ( ) ,
1296
+ examplePlugin
1297
+ ]
1298
+ } ,
1299
+ [ / < s c r i p t d e f e r = " d e f e r " s r c = " a p p _ b u n d l e .j s " > < \/ s c r i p t > [ \s ] * < \/ h e a d > / ] ,
1300
+ null , done , false , false ) ;
1301
+ } ) ;
1302
+
1235
1303
it ( 'provides the options to the afterEmit event' , done => {
1236
1304
let eventArgs ;
1237
1305
const examplePlugin = {
0 commit comments