【发布时间】:2019-09-11 14:08:46
【问题描述】:
我有一个模板文件,用于使用 html-webpack-plugin 生成最终的输出 html 文件。有没有办法在生成最终文件时包含引用的本地文件?
我的文件结构如下:
.\public\index.html
.\public\css\site.css
这是一个 index.html 模板文件:
<!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>
在 webpack.config.js 我有以下内容:
....
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html'
})
]
...
这将生成 .\dist\index.html 文件,但不会将 .\public\css\main.css 复制到 .\dist\css\main.css 中。
有没有办法做到这一点?
【问题讨论】:
-
与文件结构无关,与webpack输出配置有关,webpack.js.org/configuration/output
-
遇到同样的问题,如果我解决它,我会回来回答
标签: webpack html-webpack-plugin