Link a static JS file with HtmlWebpackPlugin

I am building an application with a custom webpack configuration.

I have integrated the HtmlWebpackPlugin with a custom index.html like so:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Text Mining</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
    <link rel="preconnect" href="" />
    <div id="app"></div>
      new HtmlWebpackPlugin({
        inject: true,
        filename: './index.html',
        template: './public/index.html',
        favicon: './public/favicon.ico',
        scripts: ['./public/static/js/env.js']

I assumed that adding the path to my static js file in the scripts array would copy env.js into the compiled html but I cannot see it.

Is there another plugin i need to copy from the public folder or am i missing something else?


I am not sure if this is a good solution, but I have recently used copy-webpack-plugin to solve a similar issue. Maybe this will help you.