You can create your own context with the
It allows you to pass in a directory to search, a flag indicating whether subdirectories should be searched too, and a regular expression to match files against.
webpack parses for
require.context() in the code while building.
The syntax is as follows:
(useSubdirectories = true),
(regExp = /^\.\/.*$/),
(mode = 'sync'));
require.context('./test', false, /\.test\.js$/);
// a context with files from the test directory that can be required with a request ending with `.test.js`.
require.context('../', true, /\.stories\.js$/);
// a context with all files in the parent folder and descending folders ending with `.stories.js`.