webpack4-- 處理html中引入的圖片
阿新 • • 發佈:2018-12-15
index.html
<img src="./src/images/current_day_icon.png" alt="">
配置
module: { rules: [{ test: /\.(png|jpg|gif)$/, use: [{ loader: 'file-loader', options: { name: '[name].[ext]', publicPath: "./images/", outputPath: "images/" } } ] }, { test: /\.(html)$/, use: { loader: 'html-loader', options: { attrs: ['img:src', 'img:data-src', 'audio:src'], minimize: true } } } ]
打包結果
必須file-loader和html-loader’同時使用才會把img打包到build/images