首页 新闻 会员 周边 捐助

html-webpack-plugin css 提取 动态的样式表变成Object怎么解决?

0
悬赏园豆:50 [待解决问题]

webpack HtmlWebpackPlugin配置
const htmlWebpackPlugin = new HtmlWebpackPlugin({
inject: false,
template: resolveApp('./src/page/index.html'),
favicon: resolveApp('./src/assets/favicon.png'),
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
minifyHTML: true
}
});
html 模板
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%=htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
<% } %>
</head>

<body>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script type="text/javascript" src="<%=htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
</body>

</html>

其中CSS代码遍历
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%=htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
<% } %>

最后得到结果是

<link rel="icon" type="image/png" href="/favicon.png">
<link href="[object Object]" rel="stylesheet">

动态的样式表变成Object怎么解决?

sheele的主页 sheele | 初学一级 | 园豆:152
提问于:2019-12-15 16:12
< >
分享
所有回答(1)
0

你可以试试把这个object打印出来看看是什么
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%=JSON.stringify(htmlWebpackPlugin.files.css[css]) %>" rel="stylesheet">
<% } %>

by.Genesis | 园豆:2824 (老鸟四级) | 2019-12-17 11:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册