@@ -8,6 +8,7 @@ const path = require('path');
88const argv = require ( 'yargs' ) . argv ;
99const { merge } = require ( 'webpack-merge' ) ;
1010const WebpackBar = require ( 'webpackbar' ) ;
11+ const fs = require ( 'node:fs' ) ;
1112
1213const cosmiconfigSync = require ( 'cosmiconfig' ) . cosmiconfigSync ;
1314const explorerSync = cosmiconfigSync ( 'patternlab' ) ;
@@ -24,6 +25,19 @@ const defaultConfig = {
2425 noViewAll : false ,
2526} ;
2627
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+
2741module . exports = function ( apiConfig ) {
2842 return new Promise ( async ( resolve ) => {
2943 let customConfig = defaultConfig ;
@@ -170,11 +184,11 @@ module.exports = function (apiConfig) {
170184 {
171185 loader : 'html-loader' ,
172186 options : {
173- interpolate : true ,
174187 minifyCSS : false ,
175188 minifyJS : config . prod ? true : false ,
176189 // super important -- this prevents the embedded iframe srcdoc HTML from breaking!
177190 preventAttributesEscaping : true ,
191+ preprocessor : processNestedHtml ,
178192 } ,
179193 } ,
180194 ] ,
0 commit comments