-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to exclude some directories/files from stories #11181
Comments
Haven't tried this, but possible solution here: |
I can't seem to make that work, it ends up excluding all files. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Is there anyway to pass options for
|
I don't think there's a mechanism in place for that, and I tried tweaking a little here but it seems like passing a @pelotom I'm not sure about your use case, but the use case I see about using exclude would be maybe if I'm developing |
My use case is that I have one particular directory of stories nested deep within my repo which I want to exclude during visual regression testing in CI. It's not practical to positively specify all the things I do want to include while omitting this one particular deeply-nested directory, if that makes sense. My short term workaround is just to delete the directory in the CI script before building the storybook, but it'd be nice to have an |
@pelotom One workaround might be to specify the export default {
title: 'path/to/MyComponent',
component: MyComponent,
parameters: {
chromatic: { disable: true },
}
}
// stories here ... |
Ah, I am using Chromatic, thanks for the tip! |
Faced same issue. We have a big library with a lot of submodules and their stories. Some submodules have their own storybook configuration due to specific code/environment. We need to exclude these submodules stories from the main storybook and cant find a way to do it with the new pattern format 😕 |
@artaommahe have you looked at storybook composition? https://medium.com/storybookjs/storybook-composition-af0da9084fba |
how does it exclude dirs from specific storybook? e.x. this folders structure
we need layout/lesson/user stories, but not widgets one for the main storybook |
you could just include |
hm, yu're right, just list all folders.. so there is no other way, no excluding in current glob implementation? |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
You're not required to specify globs! module.exports = {
stories: async (list) => [...list, ...findFilesUsingWhateverMethodYouLikeAndReturnAnArray()],
}; |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Same need for excluding SCSS files from rebuilding Storybook... when using a parallel build and injecting compiled css via This seems like a common workflow (it's mentioned in docs)... is there a workaround/solution for that already? |
I also kind of need this. Is way harder to keep everything in sync by just adding all the new folders everytime. Is kind of redundant and hard to do. This option would be extremely useful or at least a way to do it with regex. |
For anyone still struggling: You can in fact exclude stories without custom story resolver functions. First of all, these are the relevant resources (as I also explained in #10153):
Since micromatch is used, you can simply add negative patterns using Be aware of the other rules, to make sure, you are not accidentally misusing it. E.g. make sure, to keep all Example: |
I am still not getting this to work, here's my current config:
I basically want to exclude one folder inside of stories to keep it in source code for a while. I could move it out but don't really want to do that. I tried this:
|
@kelly-tock I would recommend installing Mine works fine: |
In case it's useful for anyone: Using node's glob with the ignore option worked well for me.
|
On my side, @dannyhw the disadvantage is you have to stop/restart your Storybook to take in account new story files. While developing it's a bit annoying. I recommend using in the array the standard way of Storybook with wildcards, and for a folder where you need to exclude something, you calculate fixed paths with It's not perfect until Storybook will eventually manage excluding paths natively. |
@sneko yeah you're right it doesn't work for new files, its more of a workaround. Though with the way require.context is used for importing stories I wasn't able to find another way to solve this at the time. |
@dannyhw still no other good way same 1 year later. In my case I have
|
In a pnpm workspace with storybook on vite, the const config: StorybookConfig = {
stories: [
// (...)
"../ui/**/*.stories.@(js|jsx|ts|tsx)",
"../ui/**!(/node_modules)/**/*.stories.@(js|jsx|ts|tsx)",
Probably related to |
…ook recursively sourcing symlinked workspace components. Added note to .storybook/main.ts Related to Issues: storybookjs/storybook#15913 storybookjs/storybook#11181
@D1no I had a very similar problem within a similar project setup which I managed to fix by: stories: [
"../../**!(node_modules)/**!(node_modules)/*.mdx",
"../../**!(node_modules)/**!(node_modules)/*.stories.@(js|jsx|ts|tsx)",
], See: andrejilderda/desktop-ui@0993a07 Also note that Storybook is not using micromatch but globby as a globbing library (see here). |
…atch, is used. See: storybookjs/storybook#11181 (comment) Thanks!
Thank you very much @andrejilderda ! Due to your insight I was able to add it to the following issue: #21399 Seems like it is flaky / not really user friendly but it works! Reference case "4_proper_workspace_stories_trying_to_avoid_recursion_with_glob":
configStories = [
/**
* Since storybook uses globby under the hood, trying to add a negative
* glob for nested node_modules via "**!(node_modules)/**!(node_modules)".
* -> Insight from https://github.com/storybookjs/storybook/issues/11181#issuecomment-1474347928
* though sometimes just "**!(node_modules)" seems to work, when there
* are stories directly on next level folder. The following wont work:
* "../node_modules/@repo/views/**!(node_modules)/**!(node_modules)/*.stories.@(js|jsx|ts|tsx)"
* This does:
* "../node_modules/@repo/views/**!(node_modules)/*.stories.@(js|jsx|ts|tsx)"
*/
"../node_modules/@repo/**!(node_modules)/**!(node_modules)/*.stories.@(js|jsx|ts|tsx)",
];
break; |
just to add the point - tried the above steps of glob pattern - Btw, the use-case was to skip some stories while building. And the storybook setup is 7-rc3. |
As stated before, storybook is using With a workaround, you can use Here is how I include all import type { StorybookConfig } from "@storybook/vue3-vite"
// This is already installed by storybook
import globby from "globby"
const config: StorybookConfig = {
// globby is working from the root, where "yarn storybook" was called.
// To make it work with storybooks internal logic, we have to change the cwd
stories: globby.sync([`../**/*.stories.@(js|jsx|ts|tsx)`, "!../**/node_modules/**/*"], , { cwd: "./.storybook" }),
// ...
}
export default config None of the other workarounds worked for me. |
Thanks for this solution! import type { StorybookConfig } from "@storybook/vue3-vite"
// This is already installed by storybook
import { globbySync } from "globby"
const config: StorybookConfig = {
// globby is working from the root, where "yarn storybook" was called.
// To make it work with storybooks internal logic, we have to change the cwd
stories: globbySync([`../**/*.stories.@(js|jsx|ts|tsx)`, "!../**/node_modules/**/*"], , { cwd: "./.storybook" }),
// ...
}
export default config |
Unfortunately, this breaks HMR for new files.. If you add a new This issue has to be solved internally by the Storybook team to support globby patterns as expected. |
For the record, in my case, I have a specific folder to ignore and here is what I come up with: import { readdirSync } from 'fs';
const config: StorybookConfig = {
stories: [
...readdirSync(__dirname + '/../../', { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.filter((dirent) => dirent.name !== 'to_ignore')
.map(
(dirent) =>
`../../${dirent.name}/**/src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)`
),
], |
I'm in a monorepo and some internal imports are done for modules, so I need to mix both worlds. The easiest solution for me was: // .storybook/main.ts
const environmentVariables: Record<string, string> = {
LOL: 'true',
};
export const config: StorybookConfig = {
...,
env: (config) => ({
...config,
...environmentVariables,
}),
viteFinal: {
define: {
'process.env': environmentVariables,
},
},
}; |
Just want to mention that it seems (according to the docs) Storybook now uses picomatch which may be missing some features from micromatch (why i was left scratching my head) |
pointing to |
Thanks to @pm0u. Reading the documentation for picomatch I saw that their negation operator works this way:
So ended up writing my storybook config like so: // main.ts
const config: StorybookConfig = {
// ...
stories: ['../src/!(ignoreFolder)/**/*.stories.{ts,tsx}', '../src/**/*.mdx'],
// ...
} |
Can be kinda tricky to get this right, so thought I would share my solution with anyone coming across this.
|
The new
main.js
format for specifying stories requires specifying an array of globs, e.g.With this approach it's not clear how I can exclude certain things from being included. When the stories were configured within the browser environment I was able to use
require.context
with a regex, e.g.I could walk the directory structure in node and just provide a large array of fully resolved file paths, but it'd be nice to just be able to provide a regex instead of a glob. Or is there a way to do this with globs that I'm missing?
The text was updated successfully, but these errors were encountered: