@@ -75,6 +75,7 @@ class HtmlWebpackChildCompiler {
7575 const webpack = mainCompilation . compiler . webpack ;
7676 const Compilation = webpack . Compilation ;
7777
78+ const NodeTemplatePlugin = webpack . node . NodeTemplatePlugin ;
7879 const NodeTargetPlugin = webpack . node . NodeTargetPlugin ;
7980 const LoaderTargetPlugin = webpack . LoaderTargetPlugin ;
8081 const EntryPlugin = webpack . EntryPlugin ;
@@ -103,6 +104,7 @@ class HtmlWebpackChildCompiler {
103104 const childCompiler = mainCompilation . createChildCompiler ( compilerName , outputOptions , [
104105 // Compile the template to nodejs javascript
105106 new NodeTargetPlugin ( ) ,
107+ new NodeTemplatePlugin ( ) ,
106108 new LoaderTargetPlugin ( 'node' ) ,
107109 new webpack . library . EnableLibraryPlugin ( 'var' )
108110 ] ) ;
@@ -114,10 +116,18 @@ class HtmlWebpackChildCompiler {
114116
115117 // Add all templates
116118 this . templates . forEach ( ( template , index ) => {
117- new EntryPlugin ( childCompiler . context , 'data:text/javascript,__webpack_public_path__ = htmlWebpackPluginPublicPath;' , `HtmlWebpackPlugin_${ index } -${ this . id } ` ) . apply ( childCompiler ) ;
119+ new EntryPlugin ( childCompiler . context , 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;' , `HtmlWebpackPlugin_${ index } -${ this . id } ` ) . apply ( childCompiler ) ;
118120 new EntryPlugin ( childCompiler . context , template , `HtmlWebpackPlugin_${ index } -${ this . id } ` ) . apply ( childCompiler ) ;
119121 } ) ;
120122
123+ // The templates are compiled and executed by NodeJS - similar to server side rendering
124+ // Unfortunately this causes issues as some loaders require an absolute URL to support ES Modules
125+ // The following config enables relative URL support for the child compiler
126+ childCompiler . options . module = { ...childCompiler . options . module } ;
127+ childCompiler . options . module . parser = { ...childCompiler . options . module . parser } ;
128+ childCompiler . options . module . parser . javascript = { ...childCompiler . options . module . parser . javascript ,
129+ url : 'relative' } ;
130+
121131 this . compilationStartedTimestamp = new Date ( ) . getTime ( ) ;
122132 this . compilationPromise = new Promise ( ( resolve , reject ) => {
123133 const extractedAssets = [ ] ;
0 commit comments