Skip to content

How to access environmental variables in template.html file? #1703

Answered by rschristian
micahjon asked this question in Q&A
Discussion options

You must be logged in to vote

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.…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by micahjon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants