I only want Webpack to look at files in directories called ".stories", but they can be located anywhere arbitrarily in the src/ directory structure.
For example, my naïve attempt at this looks as follows:
/*
src/
some.story.js <-- don't get this
|_components/
|_Button/
|_ .stories/ <--
|_ index.js <-- ignore this
|_ utils.js <-- ignore this
|_ main.story.js <-- get this
|_Forms/
|_ TextField
|_ .stories/ <-- same kind of thing
*/
// require.context API
// require.context(directory to search, shouldSearchSubDirs?, fileNameRegex)
require.context('src/**/.stories', true, /\.story\.js$/)
So far it seems as if the API wants me to do all my pattern matching on the file names. But the file names alone aren't enough information to exclude .story.js files in other directories. I want to allow for .story.js files outside of .stories/ directories, and have Webpack ignore them.
Is this possible? What am I missing?
When reading the official documentation, the implication is that the first argument specifies one specific directory:
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.
One reading of this is antithetical to my goal, but nothing clearly states this is impossible. Webpack is a complex tool and it's easy to misunderstand its capabilities.