Nextjs: Add TS docgen support for Vite implementation

This commit is contained in:
Yann Braga 2024-12-05 14:47:24 +01:00
parent a197110c7d
commit bac7061dcd
6 changed files with 19 additions and 5 deletions

View File

@ -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"

View File

@ -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;
};

View File

@ -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';

View File

@ -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",

View File

@ -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

View File

@ -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"