I think maybe a better idea is to use an index file for your images folder.
Supposing you have this structure:
And you need to import all of your images to your HomePage component.
You can easily create an index.js
file on your images folder, exporting all the images using require, like this:
export const Background = require('./bg/background.jpg');
export const First = require('./photos/first.jpg');
export const Second = require('./photos/second.jpg');
export const LinkedIn = require('./social/linkedin.png');
Then on your component you can import all of them with a single import.
import {
Background,
First,
Second,
LinkedIn
} from '../../assets/images'
And this would be your final folder structure:
Hope it helps! ;)
Updated on 25/04/2021:
If you want to use ES6 named imports:
images/index.js:
import Background from './bg/background.jpg';
import First from './photos/first.jpg';
import Second from './photos/second.jpg';
import LinkedIn from './social/linkedin.png';
export {
Background,
First,
Second,
LinkedIn
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…