How to access environmental variables in template.html file? #1703
-
I have environmental variables working in my JS code, but wondered if there was a way to access them in the Ideally, I could update an object in Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yep, you sure can! // preact.config.js
export default (config, env, helpers) => {
const { plugin: htmlWebpackPlugin } = helpers.getPluginsByName(config, 'HtmlWebpackPlugin')[0];
htmlWebpackPlugin.options.config.foobarbaz = true;
}; <!-- src/template.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><% preact.title %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
<% if (htmlWebpackPlugin.options.config.foobarbaz) { %>
<meta name="example-meta" content="Hello World!">
<% } %>
<% preact.headEnd %>
</head>
<body>
<% preact.bodyEnd %>
</body>
</html>
|
Beta Was this translation helpful? Give feedback.
Yep, you sure can!