@@ -86,35 +86,40 @@ export default class AppConfigPlugin implements Options {
8686
8787 injectHead ( compiler : Compiler ) {
8888 compiler . hooks . compilation . tap ( 'AppConfigPlugin' , ( compilation ) => {
89- import ( 'html-webpack-plugin' ) . then ( ( module ) => {
90- const HtmlWebpackPlugin = module . default ;
91- HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTagGroups . tapPromise (
92- 'AppConfigPlugin' ,
93- async ( { headTags, ...html } ) => {
94- // remove placeholder <script id="app-config"></script> if it exists
95- const newTags = headTags . filter (
96- ( { attributes } ) => attributes . id !== 'app-config' ,
97- ) ;
98-
99- newTags . push ( {
100- tagName : 'script' ,
101- attributes : { id : 'app-config' , type : 'text/javascript' } ,
102- innerHTML : `` ,
103- voidTag : false ,
104- meta : { } ,
105- } ) ;
106-
107- return {
108- ...html ,
109- headTags : newTags ,
110- } ;
111- } ,
112- ) ;
113- } ) . catch ( ( error ) => {
114- console . error ( error . message ) ;
115- console . error ( 'Failed to resolve html-webpack-plugin' ) ;
116- console . error ( 'Either include the module in your dependencies and enable the webpack plugin, or set headerInjection to false in your configuration.' ) ;
117- } ) ;
89+ import ( 'html-webpack-plugin' )
90+ . then ( ( module ) => {
91+ const HtmlWebpackPlugin = module . default ;
92+
93+ HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTagGroups . tapPromise (
94+ 'AppConfigPlugin' ,
95+ async ( { headTags, ...html } ) => {
96+ // remove placeholder <script id="app-config"></script> if it exists
97+ const newTags = headTags . filter ( ( { attributes } ) => attributes . id !== 'app-config' ) ;
98+
99+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
100+ newTags . push ( {
101+ tagName : 'script' ,
102+ attributes : { id : 'app-config' , type : 'text/javascript' } ,
103+ innerHTML : `` ,
104+ voidTag : false ,
105+ meta : { } ,
106+ } ) ;
107+
108+ return {
109+ ...html ,
110+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
111+ headTags : newTags ,
112+ } ;
113+ } ,
114+ ) ;
115+ } )
116+ . catch ( ( error ) => {
117+ console . error ( error . message ) ;
118+ console . error ( 'Failed to resolve html-webpack-plugin' ) ;
119+ console . error (
120+ 'Either include the module in your dependencies and enable the webpack plugin, or set headerInjection to false in your configuration.' ,
121+ ) ;
122+ } ) ;
118123 } ) ;
119124 }
120125}
0 commit comments