mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Nextjs: Add TS docgen support for Vite implementation
This commit is contained in:
parent
a197110c7d
commit
bac7061dcd
@ -97,6 +97,7 @@
|
||||
"dependencies": {
|
||||
"@storybook/builder-vite": "workspace:*",
|
||||
"@storybook/react": "workspace:*",
|
||||
"@storybook/react-vite": "workspace:*",
|
||||
"@storybook/test": "workspace:*",
|
||||
"styled-jsx": "5.1.6",
|
||||
"vite-plugin-storybook-nextjs": "^1.1.0"
|
||||
|
@ -4,6 +4,7 @@ import path from 'node:path';
|
||||
import type { PresetProperty } from 'storybook/internal/types';
|
||||
|
||||
import type { StorybookConfigVite } from '@storybook/builder-vite';
|
||||
import { viteFinal as reactViteFinal } from '@storybook/react-vite/preset';
|
||||
|
||||
import { dirname, join } from 'path';
|
||||
import vitePluginStorybookNextjs from 'vite-plugin-storybook-nextjs';
|
||||
@ -34,11 +35,13 @@ export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entry =
|
||||
};
|
||||
|
||||
export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, options) => {
|
||||
config.plugins = config.plugins || [];
|
||||
const reactConfig = await reactViteFinal(config, options);
|
||||
const { plugins = [] } = reactConfig;
|
||||
|
||||
const { nextConfigPath } = await options.presets.apply<FrameworkOptions>('frameworkOptions');
|
||||
|
||||
const nextDir = nextConfigPath ? path.dirname(nextConfigPath) : undefined;
|
||||
config.plugins.push(vitePluginStorybookNextjs({ dir: nextDir }));
|
||||
plugins.push(vitePluginStorybookNextjs({ dir: nextDir }));
|
||||
|
||||
return config;
|
||||
return reactConfig;
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
// @ts-expect-error FIXME
|
||||
import { viteFinal as reactViteFinal } from '@storybook/react-vite/preset';
|
||||
|
||||
import { esbuildFlowPlugin, flowPlugin } from '@bunchtogether/vite-plugin-flow';
|
||||
|
@ -32,6 +32,16 @@
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"dist/index.d.ts"
|
||||
],
|
||||
"preset": [
|
||||
"dist/preset.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -12,7 +12,7 @@ export const core: PresetProperty<'core'> = {
|
||||
renderer: getAbsolutePath('@storybook/react'),
|
||||
};
|
||||
|
||||
export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
|
||||
export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (config, { presets }) => {
|
||||
const { plugins = [] } = config;
|
||||
|
||||
// Add docgen plugin
|
||||
|
@ -6658,6 +6658,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@storybook/builder-vite": "workspace:*"
|
||||
"@storybook/react": "workspace:*"
|
||||
"@storybook/react-vite": "workspace:*"
|
||||
"@storybook/test": "workspace:*"
|
||||
"@types/node": "npm:^18.0.0"
|
||||
next: "npm:^15.0.3"
|
||||
|
Loading…
x
Reference in New Issue
Block a user