const requireContext = require.context('./image', true, /^\.\/.*\.png$/);
let iconImages = {};
requireContext.keys().map(req => {
let iconName = req.split('./')[1];
iconName = iconName.split('.')[0];
const iconNameObj = {};
iconNameObj[iconName] = require(`./image/${iconName}.png`);
iconImages = {
...iconImages,
...iconNameObj,
};
return {
iconName: require(`./image/${iconName}.png`),
};
});
console.log('requireContext', requireContext, requireContext.keys(), iconImages);
网友评论