1

例如,如果我有一个test.html文件,代码是:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8"/>
  <title>test</title>
  <link rel="stylesheet" href="/styles/test.css">
  <style>
    .test {
      background: url("/images/banner.jpg");
    }
  </style>
</head>
<body>
<img src="/images/banner.jpg" alt="test"/>
</body>
</html>

我曾经html-loader要求它,就像:

const html = require(test.html);
console.log(html);

和变量html打印:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8"/>
  <title>test</title>
  <link rel="stylesheet" href="[object Object]">
  <style>
    .test {
      background: url("/images/banner.jpg");
    }
  </style>
</head>
<body>
<img src="/temp/images/banner.d0f7ff.jpg" alt="test"/>
</body>
</html>

style-> .test->background无法获得正确的网址。如何解决?

这是我的webpack配置代码html-loader

{
  test: /\.html$/,
  include: [
    path.resolve(config.devDir)
  ],
  loader: 'html',
  query: {
    root: config.devDir,
    attrs: ['img:src', 'img:data-src', 'link:href']
  }
}
4

0 回答 0