Search code examples
javascriptreactjsstorybook

Storybook - Find all .stories files regardless of location


I'm using storybook and I have stories in various locations across my application. Is it possible to pull them all into storybook, without having to specify the pattern for each in the stories array in main.js.

Currently I'm doing this to find them, but I'd rather not have to specify each path if possible. Is there a pattern to find every story from the root down?

module.exports = {
  stories: [
    '../stories/**/*.stories.@(js|jsx|ts|tsx)',
    '../libs/**/src/lib/*/*.stories.@(js|jsx|ts|tsx)',
    '../stories/**/**/*.stories.@(js|jsx|ts|tsx)',
  ],
};

Solution

  • This one should do, given your patterns in the question above. With this code, you can place the files in any subfolder of the parent folder. ** means any number of intermediary folders in the path.

    module.exports = {
      stories: [
        '../**/*.stories.@(js|jsx|ts|tsx)',
      ],
    };