require.context is a webpack built-in function that allows you to pass in a directory to search, a flag indicating whether subdirectories should be examined too, and a regular expression to match files.
When the building process starts, webpack will search for all the require.context functions and will pre-execute them, so the files needed on the import will be there for the final build.
We pass three arguments to the function: the first is the folder where it will start the search, the second asks whether the search will go to descending folders, and finally, the third is a regular expression for filename matching.
In this recipe, to automatically load the routes as the first argument of the function, we define ./routes for the folder. As the second argument of the function, we define false to not search in subdirectories. Finally, as the third argument, we define /^(?!.*test).*\.js$/is as the Regex to search for .js files and ignore the files that have .test in their...