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

后端 未结 2 643
故里飘歌
故里飘歌 2021-01-15 21:58

I am using .pug templates for my HTML and standard src attributes on my images like so:

img(src=`../images/${image}`)
相关标签:
2条回答
  • 2021-01-15 22:44

    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.

    0 讨论(0)
  • 2021-01-15 22:59

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

    0 讨论(0)
提交回复
热议问题