Skip to content

Commit 35e13c6

Browse files
committed
refactor(html-loader): interpolate option got removed
that for we need to adapt some other solution for the new preprocessor option
1 parent b677703 commit 35e13c6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/uikit-workshop/src/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<!-- the template for the modal slider -->
3232
<script type="text/mustache" class="pl-js-panel-template-base">
33-
${require('./partials/base-template.html') }
33+
<include src="partials/base-template.html"/>
3434
</script>
3535

3636
<!-- webpackIgnore: true -->

packages/uikit-workshop/webpack.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path');
88
const argv = require('yargs').argv;
99
const { merge } = require('webpack-merge');
1010
const WebpackBar = require('webpackbar');
11+
const fs = require('node:fs');
1112

1213
const cosmiconfigSync = require('cosmiconfig').cosmiconfigSync;
1314
const 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 = /\<include src=\"(.+)\"\/?\>(?:\<\/include\>)?/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+
2741
module.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

Comments
 (0)