sheele 2019-12-15 16:08 采纳率: 0%
浏览 426
已结题

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

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怎么解决?
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-12-16 00:10
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题