I
I
Irina2022-03-22 23:22:23
JavaScript
Irina, 2022-03-22 23:22:23

How to make friends HtmlWebpackPlugin and html-loader?

There is a config

webpack

plugins: [
    new HtmlWebpackPlugin({
      templateParameters: {
        title: 'Title for site',
      },
      template: path.resolve(__dirname, './src/index.html'), 
      filename: 'index.html'
    })
  ],
{...}
    rules: [
      {
        test: /\.html$/i,
        use: ['html-loader']
      }
]


It seems to be working fine, without errors - except that there is no replacement of template values. Those. remains in the html file: instead of the necessary substitutions from templateParameters. Webpack 5, no matter how much I googled, I could not find the necessary settings. If anyone has experienced something similar, please provide a solution.
<title><%= title %></title>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2022-03-23
@politon

plugins: [
      new HTMLWebpackPlugin({
        title: 'Title for site',
        template: path.resolve(__dirname, './src/index.html'), 
        filename: 'index.html'
      })
  ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question