@@ -75,6 +75,7 @@ class HtmlWebpackChildCompiler {
75
75
const webpack = mainCompilation . compiler . webpack ;
76
76
const Compilation = webpack . Compilation ;
77
77
78
+ const NodeTemplatePlugin = webpack . node . NodeTemplatePlugin ;
78
79
const NodeTargetPlugin = webpack . node . NodeTargetPlugin ;
79
80
const LoaderTargetPlugin = webpack . LoaderTargetPlugin ;
80
81
const EntryPlugin = webpack . EntryPlugin ;
@@ -103,6 +104,7 @@ class HtmlWebpackChildCompiler {
103
104
const childCompiler = mainCompilation . createChildCompiler ( compilerName , outputOptions , [
104
105
// Compile the template to nodejs javascript
105
106
new NodeTargetPlugin ( ) ,
107
+ new NodeTemplatePlugin ( ) ,
106
108
new LoaderTargetPlugin ( 'node' ) ,
107
109
new webpack . library . EnableLibraryPlugin ( 'var' )
108
110
] ) ;
@@ -114,10 +116,18 @@ class HtmlWebpackChildCompiler {
114
116
115
117
// Add all templates
116
118
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 ) ;
118
120
new EntryPlugin ( childCompiler . context , template , `HtmlWebpackPlugin_${ index } -${ this . id } ` ) . apply ( childCompiler ) ;
119
121
} ) ;
120
122
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
+
121
131
this . compilationStartedTimestamp = new Date ( ) . getTime ( ) ;
122
132
this . compilationPromise = new Promise ( ( resolve , reject ) => {
123
133
const extractedAssets = [ ] ;
0 commit comments