@@ -750,6 +750,72 @@ describe('HtmlWebpackPlugin', function () {
750750 } , false , true ) ;
751751 } ) ;
752752
753+ it ( 'allows events to add a no-value attribute' , function ( done ) {
754+ var examplePlugin = {
755+ apply : function ( compiler ) {
756+ compiler . plugin ( 'compilation' , function ( compilation ) {
757+ compilation . plugin ( 'html-webpack-plugin-alter-asset-tags' , function ( pluginArgs , callback ) {
758+ pluginArgs . body = pluginArgs . body . map ( tag => {
759+ if ( tag . tagName === 'script' ) {
760+ tag . attributes . async = true ;
761+ }
762+ return tag ;
763+ } ) ;
764+ callback ( null , pluginArgs ) ;
765+ } ) ;
766+ } ) ;
767+ }
768+ } ;
769+ testHtmlPlugin ( {
770+ entry : {
771+ app : path . join ( __dirname , 'fixtures/index.js' )
772+ } ,
773+ output : {
774+ path : OUTPUT_DIR ,
775+ filename : '[name]_bundle.js'
776+ } ,
777+ plugins : [
778+ new HtmlWebpackPlugin ( ) ,
779+ examplePlugin
780+ ]
781+ } ,
782+ [ / < b o d y > [ \s ] * < s c r i p t t y p e = " t e x t \/ j a v a s c r i p t " s r c = " a p p _ b u n d l e .j s " a s y n c > < \/ s c r i p t > [ \s ] * < \/ b o d y > / ] ,
783+ null , done , false , false ) ;
784+ } ) ;
785+
786+ it ( 'allows events to remove an attribute by setting it to false' , function ( done ) {
787+ var examplePlugin = {
788+ apply : function ( compiler ) {
789+ compiler . plugin ( 'compilation' , function ( compilation ) {
790+ compilation . plugin ( 'html-webpack-plugin-alter-asset-tags' , function ( pluginArgs , callback ) {
791+ pluginArgs . body = pluginArgs . body . map ( tag => {
792+ if ( tag . tagName === 'script' ) {
793+ tag . attributes . async = false ;
794+ }
795+ return tag ;
796+ } ) ;
797+ callback ( null , pluginArgs ) ;
798+ } ) ;
799+ } ) ;
800+ }
801+ } ;
802+ testHtmlPlugin ( {
803+ entry : {
804+ app : path . join ( __dirname , 'fixtures/index.js' )
805+ } ,
806+ output : {
807+ path : OUTPUT_DIR ,
808+ filename : '[name]_bundle.js'
809+ } ,
810+ plugins : [
811+ new HtmlWebpackPlugin ( ) ,
812+ examplePlugin
813+ ]
814+ } ,
815+ [ / < b o d y > [ \s ] * < s c r i p t t y p e = " t e x t \/ j a v a s c r i p t " s r c = " a p p _ b u n d l e .j s " > < \/ s c r i p t > [ \s ] * < \/ b o d y > / ] ,
816+ null , done , false , false ) ;
817+ } ) ;
818+
753819 it ( 'fires the html-webpack-plugin-before-html-processing event' , function ( done ) {
754820 var eventFired = false ;
755821 var examplePlugin = {
0 commit comments