fix hmr not working in template files

This commit is contained in:
Ray Elliott 2021-01-07 13:36:36 +00:00
parent 5c04c58f6a
commit b4c4d4b233
4 changed files with 13 additions and 7 deletions

View File

@ -5,7 +5,8 @@
"private": true, "private": true,
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack serve", "serve": "webpack serve",
"watch": "webpack --watch --progress",
"build": "webpack --env production" "build": "webpack --env production"
}, },
"author": "", "author": "",

View File

@ -19,8 +19,8 @@
</header> </header>
<main id="js-main"> <main id="js-main">
<% let data = {text: 'text is text'} %> <%# weird loader string syntax because https://github.com/bazilio91/ejs-compiled-loader/issues/46 %>
<%- include partials/component data %> <%- require('!!ejs-compiled-loader?{}!./partials/component.ejs')({ text: 'text is text yahh!!!' }) %>
</main> </main>
<footer> <footer>

View File

@ -1,3 +1,4 @@
<div class="component"> <div class="component">
<p><%= data.text %></p> <p><%= text %></p>
<p>woot!</p>
</div> </div>

View File

@ -25,7 +25,8 @@ module.exports = (env) => ({
}), }),
new CleanWebpackPlugin(), new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './src/templates/index.ejs', // weird loader string syntax because https://github.com/bazilio91/ejs-compiled-loader/issues/46
template: '!!ejs-compiled-loader?{}!./src/templates/index.ejs',
}), }),
new EsLintPlugin(), new EsLintPlugin(),
new StylelintPlugin(), new StylelintPlugin(),
@ -35,8 +36,11 @@ module.exports = (env) => ({
{ {
test: /\.ejs$/, test: /\.ejs$/,
use: { use: {
loader: 'ejs-compiled-loader', // weird loader string syntax because https://github.com/bazilio91/ejs-compiled-loader/issues/46
options: {}, // supply empty options object because of https://github.com/bazilio91/ejs-compiled-loader/issues/46 // NOTE - talso an alternative workaround that involves passing
// the usual 'ejs-compiled-loader' as the loader and passing
// an empty options object, however hmr did not work with that fix.
loader: '!!ejs-compiled-loader?{}!',
}, },
}, },
{ {