如何在webpack中URL加载多个图像? [英] How to url-loader multiple images in webpack?

查看:163
本文介绍了如何在webpack中URL加载多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的webpack配置:

My webpack config:

{ test: /\.(png|jpg)$/, loader: 'url?limit=8192' }

在我的项目中,我必须像这样加载图像:

In my project, I must loader images like this:

import homeBg1 from './image/homeBg1.jpg';
import homeBg2 from './image/homeBg2.jpg';
import homeBg3 from './image/homeBg3.jpg';

操作繁琐,谁能给我一些建议?谢谢!

The operating cumbersome, who can give me some advice?Thx!

推荐答案

此代码将从image文件夹中导入所有* .jpg文件:

This code will import all *.jpg files from image folder:

var requireContext = require.context("./image", true, /^\.\/.*\.jpg$/);
requireContext.keys().map(requireContext);

有关require.context的更多信息: https://webpack.github.io/docs/context.html#require-context

这篇关于如何在webpack中URL加载多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆