@@ -8,6 +8,7 @@ const path = require('path');
8
8
const argv = require ( 'yargs' ) . argv ;
9
9
const { merge } = require ( 'webpack-merge' ) ;
10
10
const WebpackBar = require ( 'webpackbar' ) ;
11
+ const fs = require ( 'node:fs' ) ;
11
12
12
13
const cosmiconfigSync = require ( 'cosmiconfig' ) . cosmiconfigSync ;
13
14
const explorerSync = cosmiconfigSync ( 'patternlab' ) ;
@@ -24,6 +25,19 @@ const defaultConfig = {
24
25
noViewAll : false ,
25
26
} ;
26
27
28
+ // Requiring partials
29
+ // adapted from https://github.com/webpack-contrib/html-loader/issues/291#issuecomment-721909576
30
+ const INCLUDE_PATTERN = / \< i n c l u d e s r c = \" ( .+ ) \" \/ ? \> (?: \< \/ i n c l u d e \> ) ? / gi;
31
+ const processNestedHtml = ( content , loaderContext ) =>
32
+ ! INCLUDE_PATTERN . test ( content )
33
+ ? content
34
+ : content . replace ( INCLUDE_PATTERN , ( m , src ) =>
35
+ processNestedHtml (
36
+ fs . readFileSync ( path . resolve ( loaderContext . context , src ) , 'utf8' ) ,
37
+ loaderContext
38
+ )
39
+ ) ;
40
+
27
41
module . exports = function ( apiConfig ) {
28
42
return new Promise ( async ( resolve ) => {
29
43
let customConfig = defaultConfig ;
@@ -170,11 +184,11 @@ module.exports = function (apiConfig) {
170
184
{
171
185
loader : 'html-loader' ,
172
186
options : {
173
- interpolate : true ,
174
187
minifyCSS : false ,
175
188
minifyJS : config . prod ? true : false ,
176
189
// super important -- this prevents the embedded iframe srcdoc HTML from breaking!
177
190
preventAttributesEscaping : true ,
191
+ preprocessor : processNestedHtml ,
178
192
} ,
179
193
} ,
180
194
] ,
0 commit comments