2

I have a template file which I use to generate the final output html file using the html-webpack-plugin. Is there a way to include referenced local files when generating the final file?

I have the following file structure:

.\public\index.html
.\public\css\site.css

Here is an index.html template file:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title><%= htmlWebpackPlugin.options.title %></title>
    <link href="css/site.css" rel="stylesheet" />
</head>
<body>
    <div id="app"></div>
</body>
</html>

Inside the webpack.config.js I have the following:

....
plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ]
...

This will generate the .\dist\index.html file, however it will not copy over the .\public\css\main.css into .\dist\css\main.css.

Is there a way to do this?

Dalibor Čarapić
  • 2,792
  • 23
  • 38

1 Answers1

0

From this answer it's stated that you need to copy the static files to dist when you are building your application if you want to use your own CSS and Html.

For that, you can use the following plugin

And add the following lines in your webpack config in plugin session to do it in

 new CopyPlugin([{ from: "path/to/your/static", to: "/path/to/your/static/in/dist" }])

remember to import the plugin at the beginning of your file.

Espoir Murhabazi
  • 5,973
  • 5
  • 42
  • 73