关于Webpack 静态Html中 图片打包的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/csdnlinyongsheng/article/details/82149665

解决方案有三种:

1.通过import方式引入图片;

例:import imgUrl from 'path/to/..png';

2.通过CommonJS方式引入;

var imgUrl = requrie('path/to/..png');

3.通过html-loader插件方式来解决;

步骤:一、npm install -d html-loader;

           二、把下面代码放入webpack.config.js配置里:

           {
              test: /\.(html)$/,
              use: {
                   loader: 'html-loader',
                   options: {
                         attrs: ['img:src', 'img:data-src', 'audio:src'],

                         minimize:true
                   }
             }
          }

猜你喜欢

转载自blog.csdn.net/csdnlinyongsheng/article/details/82149665