1

I am trying to replace a title and a version number in my HTML. I cannit get the variables to be replaced. The final output still includes the variable names.

My webpack config contains:

const HtmlWebpackPluginConfig = {
  template: path.join(__dirname, '/client/index.html'),
  inject: 'body',
  commitHash: 'hello',
  filename: '/index.html',
  title: 'My App'
};

and my index.html is:

<!DOCTYPE html>
<html>
  <head>
    <title>{%= htmlWebpackPlugin.options.title %}</title>
    <meta charset="UTF-8"/>
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <link rel="manifest" href="/manifest.json">
    <meta name="version" content="{%= htmlWebpackPlugin.options.commitHash %}">

  </head>
  <body>
    <div id="react-view" ></div>
  </body>
</html>

The final output is pretty much the same as the index.html file (with the react element filled in).

What am I doing wrong? How do I get the variables to be replaced?

1 Answer 1

1

The problem was that I was using curly brackets instead of angle brackets.

I should have written

<title><%= htmlWebpackPlugin.options.title %></title>
Sign up to request clarification or add additional context in comments.

1 Comment

are you using some kind of templating engine there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.