【发布时间】:2017-03-15 15:51:57
【问题描述】:
我正在使用 webpack 构建一个单页应用程序,以使用 HtmlWebpackPlugin 构建 main.<hash>.js、main.<hash>.css 和 index.html。
这会将包注入index.html
<script type="text/javascript" src="/static/js/main.4d67bd1c.js"></script>
在正文中,并且
<link href="/static/css/main.f6908217.css" rel="stylesheet">
在头脑中。
如何在 href 和 src 中包含主机?我曾尝试使用带有 HtmlWebpackPlugin 的自定义模板,但我不确定如何获取已编译包 js/css 的路径。
HtmlWebpackPlugin 配置如下:
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
})
(这基本上直接来自 create-react-app)
【问题讨论】:
标签: webpack