首页 > 解决方案 > CSS 未包含在 index.html 中

问题描述

我有一些 CSS 规则,其中之一是:

  {
    test: /\.css$/,
    use: [{ loader: 'style-loader/url' }, { loader: 'file-loader' }],
    include: [require.resolve('normalize.css')],
  },

该规则非常具体,仅匹配单个导入,即在我的内部我index.js有一个导入:

import 'normalize.css';

当我构建(使用 WebPack 4)时,我在输出中看到index.html多个:

<link href="/2.03ec883f8c956db4d531.css" rel="stylesheet">
<link href="/0.6e0b40d9554f38994c59.css" rel="stylesheet">

对于其他 css 规则,但没有对normalize.cssbundle 的引用。它在dist文件名为fda27b856c2e3cada6e0f6bfeccc2067.css(nicely minimized, and this file only contains normalize.css) 的文件夹中可用,但fda27b856c2e3cada6e0f6bfeccc2067.cssindex.html.

我该如何解决?

标签: webpackwebpack-4webpack-style-loader

解决方案


推荐阅读