Answer the question
In order to leave comments, you need to log in
How to correctly pass values to a template in Webpack 4?
Greetings!
It is necessary in Webpack 4 to pass a parameter to the template.
1. Googled the following implementation: https://github.com/jantimon/html-webpack-plugin/bl...
2. Changed the assembly in accordance with the example above, got the parameter in the template, everything is ok.
webpack.config.js:
new HtmlWebpackPlugin({
template: 'src/page_landing_1.ejs',
filename: "page_landing_1.html",
templateParameters: {"prop": true},
}),
<% if(prop) { %>
<h1><%= prop %></h1>
<% } %>
<%- include('header'); -%>
<% if(prop) { %>
<h1><%= prop %></h1>
<% } %>
ERROR in ./src/page_landing_1.ejs (./node_modules/html-webpack-plugin/lib/loader.js!./src/page_landing_1.ejs)
Module build failed (from ./node_modules/html-webpack-plugin/lib/loader.js):
SyntaxError: missing ) after argument list
Answer the question
In order to leave comments, you need to log in
Question 3: with this implementation, the connection of other templates (header and footer) to the current template falls off. What to do?
module: {
rules: [
{
test: /\.ejs$/,
use: [
{
loader: "ejs-webpack-loader",
options: {
data: {prop: true},
htmlmin: true
}
}
]
},
]
}
<%- include header.html -%>
<% if(prop) { %>
<h1><%= prop %></h1>
<% } %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question