1.安装依赖
npm i url-loader -D
2.js 中使用图片
import logo from ‘./image/1.png‘ let image = new Image(); image.src = logo; document.body.appendChild(image);
3. webpack.config.js
{ test: /\.(jpg|png|bmp|gif|svg)/, use: [ { loader: ‘url-loader‘, options: { limit: 4096 } } ] },
4. 测试
图片正常显示出来
原文:https://www.cnblogs.com/guangzhou11/p/12466366.html