How to get image that is within a data attrbute with Webpack 2?

孤街浪徒 提交于 2019-12-01 13:55:58

Okay. It turns out that html-loader has an option to pass in tag / attribute types for the loader to parse through, called attrs, which is an array of these configurations.

I achieved this doing it like so:

{
  test: /\.pug$/,
  use: [
    {
      loader: 'html-loader',
      options: {
        attrs: ['img:src', 'img:data-src', 'link:href']
      }
    },
    {
      loader: 'pug-html-loader',
      options: {
        pretty: true,
        exports: false
      }
    }
  ]
}

Now running webpack -p appears to get those images.

Hope that this helps someone out sometime.

options can still bug with html-loader. You might need to use this instead https://webpack.js.org/plugins/loader-options-plugin/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!