Skip to content

Commit fc1a9d5

Browse files
authored
Merge pull request #32319 from storybookjs/copilot/fix-32318
Svelte & Vue: Add framework-specific `docgen` option to disable docgen processing
2 parents 197ef41 + 8de12c5 commit fc1a9d5

File tree

9 files changed

+119
-10
lines changed

9 files changed

+119
-10
lines changed

code/frameworks/svelte-vite/src/preset.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PresetProperty } from 'storybook/internal/types';
22

33
import { svelteDocgen } from './plugins/svelte-docgen';
4-
import type { StorybookConfig } from './types';
4+
import type { FrameworkOptions, StorybookConfig } from './types';
55
import { handleSvelteKit } from './utils';
66

77
export const core: PresetProperty<'core'> = {
@@ -12,7 +12,15 @@ export const core: PresetProperty<'core'> = {
1212
export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (config, options) => {
1313
const { plugins = [] } = config;
1414

15-
plugins.push(await svelteDocgen());
15+
// Get framework options to check if docgen is disabled
16+
const framework = await options.presets.apply('framework');
17+
const frameworkOptions: FrameworkOptions =
18+
typeof framework === 'string' ? {} : (framework.options ?? {});
19+
20+
// Check if docgen is disabled in framework options (default is true/enabled)
21+
if (frameworkOptions.docgen !== false) {
22+
plugins.push(await svelteDocgen());
23+
}
1624

1725
await handleSvelteKit(plugins, options);
1826

code/frameworks/svelte-vite/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ type BuilderName = CompatibleString<'@storybook/builder-vite'>;
1010

1111
export type FrameworkOptions = {
1212
builder?: BuilderOptions;
13+
/**
14+
* Enable or disable automatic documentation generation for component properties, events, and
15+
* slots. When disabled, Storybook will skip the docgen processing step during build, which can
16+
* improve build performance.
17+
*
18+
* @default true
19+
*/
20+
docgen?: boolean;
1321
};
1422

1523
type StorybookConfigFramework = {

code/frameworks/sveltekit/src/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { viteFinal as svelteViteFinal } from '@storybook/svelte-vite/preset';
77

88
import { configOverrides } from './plugins/config-overrides';
99
import { mockSveltekitStores } from './plugins/mock-sveltekit-stores';
10-
import { type StorybookConfig } from './types';
10+
import { type FrameworkOptions, type StorybookConfig } from './types';
1111

1212
export const core: PresetProperty<'core'> = {
1313
builder: import.meta.resolve('@storybook/builder-vite'),

code/frameworks/sveltekit/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ type BuilderName = CompatibleString<'@storybook/builder-vite'>;
1313

1414
export type FrameworkOptions = {
1515
builder?: BuilderOptions;
16+
/**
17+
* Enable or disable automatic documentation generation for component properties, events, and
18+
* slots. When disabled, Storybook will skip the docgen processing step during build, which can
19+
* improve build performance.
20+
*
21+
* @default true
22+
*/
23+
docgen?: boolean;
1624
};
1725

1826
type StorybookConfigFramework = {

code/frameworks/vue3-vite/src/preset.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) =
2222
const docgen = resolveDocgenOptions(frameworkOptions.docgen);
2323

2424
// add docgen plugin depending on framework option
25-
if (docgen.plugin === 'vue-component-meta') {
26-
plugins.push(await vueComponentMeta(docgen.tsconfig));
27-
} else {
28-
plugins.push(await vueDocgen());
25+
if (docgen !== false) {
26+
if (docgen.plugin === 'vue-component-meta') {
27+
plugins.push(await vueComponentMeta(docgen.tsconfig));
28+
} else {
29+
plugins.push(await vueDocgen());
30+
}
2931
}
3032

3133
const { mergeConfig } = await import('vite');
@@ -37,13 +39,18 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) =
3739
/** Resolves the docgen framework option. */
3840
const resolveDocgenOptions = (
3941
docgen?: FrameworkOptions['docgen']
40-
): { plugin: VueDocgenPlugin; tsconfig?: string } => {
41-
if (!docgen) {
42+
): false | { plugin: VueDocgenPlugin; tsconfig?: string } => {
43+
if (docgen === false) {
44+
return false;
45+
}
46+
47+
if (docgen === undefined || docgen === true) {
4248
return { plugin: 'vue-docgen-api' };
4349
}
4450

4551
if (typeof docgen === 'string') {
4652
return { plugin: docgen };
4753
}
54+
4855
return docgen;
4956
};

code/frameworks/vue3-vite/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ export type FrameworkOptions = {
2424
* "vue-component-meta" will become the new default in the future and "vue-docgen-api" will be
2525
* removed.
2626
*
27+
* Set to `false` to disable docgen processing entirely for improved build performance.
28+
*
2729
* @default 'vue-docgen-api'
2830
*/
2931
docgen?:
32+
| boolean
3033
| VueDocgenPlugin
3134
| {
3235
plugin: 'vue-component-meta';

docs/get-started/frameworks/svelte-vite.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,30 @@ The available options are:
194194
Type: `Record<string, any>`
195195

196196
Configure options for the [framework's builder](../../api/main-config/main-config-framework.mdx#optionsbuilder). For this framework, available options can be found in the [Vite builder docs](../../builders/vite.mdx).
197+
198+
#### `docgen`
199+
200+
Type: `boolean`
201+
202+
Default: `true`
203+
204+
Enables or disables automatic documentation generation for component properties. When disabled, Storybook will skip the docgen processing step during build, which can improve build performance.
205+
206+
```ts title=".storybook/main.ts"
207+
import type { StorybookConfig } from '@storybook/svelte-vite';
208+
209+
const config: StorybookConfig = {
210+
framework: {
211+
name: '@storybook/svelte-vite',
212+
options: {
213+
docgen: false, // Disable docgen for better performance
214+
},
215+
},
216+
};
217+
218+
export default config;
219+
```
220+
221+
##### When to disable docgen
222+
223+
Disabling docgen can improve build performance for large projects, but [argTypes won't be inferred automatically](../../api/arg-types.mdx#automatic-argtype-inference), which will prevent features like [Controls](../../essentials/controls.mdx) and [docs](../../writing-docs/autodocs.mdx) from working as expected. To use those features, you will need to [define `argTypes` manually](../../api/arg-types.mdx#manually-specifying-argtypes).

docs/get-started/frameworks/sveltekit.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,33 @@ Type: `Record<string, any>`
369369

370370
Configure options for the [framework's builder](../../api/main-config/main-config-framework.mdx#optionsbuilder). For Sveltekit, available options can be found in the [Vite builder docs](../../builders/vite.mdx).
371371

372+
#### `docgen`
373+
374+
Type: `boolean`
375+
376+
Default: `true`
377+
378+
Enables or disables automatic documentation generation for component properties. When disabled, Storybook will skip the docgen processing step during build, which can improve build performance.
379+
380+
```ts title=".storybook/main.ts"
381+
import type { StorybookConfig } from '@storybook/sveltekit';
382+
383+
const config: StorybookConfig = {
384+
framework: {
385+
name: '@storybook/sveltekit',
386+
options: {
387+
docgen: false, // Disable docgen for better performance
388+
},
389+
},
390+
};
391+
392+
export default config;
393+
```
394+
395+
##### When to disable docgen
396+
397+
Disabling docgen can improve build performance for large projects, but [argTypes won't be inferred automatically](../../api/arg-types.mdx#automatic-argtype-inference), which will prevent features like [Controls](../../essentials/controls.mdx) and [docs](../../writing-docs/autodocs.mdx) from working as expected. To use those features, you will need to [define `argTypes` manually](../../api/arg-types.mdx#manually-specifying-argtypes).
398+
372399
## Troubleshooting
373400

374401
### Error when starting Storybook

docs/get-started/frameworks/vue3-vite.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,31 @@ Configure options for the [framework's builder](../../api/main-config/main-confi
288288

289289
#### `docgen`
290290

291-
Type: `'vue-docgen-api' | 'vue-component-meta'`
291+
Type: `'vue-docgen-api' | 'vue-component-meta' | boolean`
292292

293293
Default: `'vue-docgen-api'`
294294

295295
Since: `8.0`
296296

297297
Choose which docgen tool to use when generating controls for your components. See [Using `vue-component-meta`](#using-vue-component-meta) for more information.
298+
299+
Set to `false` to disable docgen processing entirely for improved build performance.
300+
301+
```ts title=".storybook/main.ts"
302+
import type { StorybookConfig } from '@storybook/vue3-vite';
303+
304+
const config: StorybookConfig = {
305+
framework: {
306+
name: '@storybook/vue3-vite',
307+
options: {
308+
docgen: false, // Disable docgen for better performance
309+
},
310+
},
311+
};
312+
313+
export default config;
314+
```
315+
316+
##### When to disable docgen
317+
318+
Disabling docgen can improve build performance for large projects, but [argTypes won't be inferred automatically](../../api/arg-types.mdx#automatic-argtype-inference), which will prevent features like [Controls](../../essentials/controls.mdx) and [docs](../../writing-docs/autodocs.mdx) from working as expected. To use those features, you will need to [define `argTypes` manually](../../api/arg-types.mdx#manually-specifying-argtypes).

0 commit comments

Comments
 (0)