问题
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!
回答1:
This code will import all *.jpg files from image
folder:
var requireContext = require.context("./image", true, /^\.\/.*\.jpg$/);
requireContext.keys().map(requireContext);
More about require.context
: https://webpack.github.io/docs/context.html#require-context
来源:https://stackoverflow.com/questions/37313954/how-to-url-loader-multiple-images-in-webpack