Skip to content
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

Vite: Fix static source handling for addon-docs #20147

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/lib/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
"@storybook/client-logger": "7.0.0-alpha.62",
"@storybook/core-common": "7.0.0-alpha.62",
"@storybook/csf-plugin": "7.0.0-alpha.62",
"@storybook/mdx2-csf": "next",
"@storybook/node-logger": "7.0.0-alpha.62",
"@storybook/preview": "7.0.0-alpha.62",
"@storybook/preview-api": "7.0.0-alpha.62",
"@storybook/source-loader": "7.0.0-alpha.62",
"@storybook/types": "7.0.0-alpha.62",
"@vitejs/plugin-react": "^2.0.0",
"browser-assert": "^1.2.1",
Expand Down
15 changes: 15 additions & 0 deletions code/lib/builder-vite/src/plugins/csf-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Plugin } from 'vite';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept a plugin so vite-config stayed clean

import { vite } from '@storybook/csf-plugin';
import type { StorybookConfig } from '@storybook/types';
import type { ExtendedOptions } from '../types';

export async function csfPlugin(config: ExtendedOptions): Promise<Plugin> {
const { presets } = config;

const addons = await presets.apply<StorybookConfig['addons']>('addons', []);
const docsOptions =
// @ts-expect-error - not sure what type to use here
addons.find((a) => [a, a.name].includes('@storybook/addon-docs'))?.options ?? {};

return vite(docsOptions?.csfPluginOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels to me like @storybook/csf-plugin itself should take care of this...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think csf-plugin should know about the user's main.js and it makes sense for addon-docs to glue things together like this. Hopefully this all goes away in 7.x with the annotations server & simplifies things even further.

}
2 changes: 1 addition & 1 deletion code/lib/builder-vite/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './inject-export-order-plugin';
export * from './mdx-plugin';
export * from './strip-story-hmr-boundaries';
export * from './code-generator-plugin';
export * from './source-loader-plugin';
export * from './csf-plugin';
104 changes: 0 additions & 104 deletions code/lib/builder-vite/src/plugins/source-loader-plugin.ts

This file was deleted.

3 changes: 2 additions & 1 deletion code/lib/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isPreservingSymlinks, getFrameworkName } from '@storybook/core-common';
import { globals } from '@storybook/preview/globals';
import {
codeGeneratorPlugin,
csfPlugin,
injectExportOrderPlugin,
mdxPlugin,
stripStoryHMRBoundary,
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function pluginConfig(options: ExtendedOptions) {

const plugins = [
codeGeneratorPlugin(options),
// sourceLoaderPlugin(options),
await csfPlugin(options),
mdxPlugin(options),
injectExportOrderPlugin,
stripStoryHMRBoundary(),
Expand Down
2 changes: 0 additions & 2 deletions code/ui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { vite as csfPlugin } from '@storybook/csf-plugin';
import pluginTurbosnap from 'vite-plugin-turbosnap';
import type { StorybookConfig } from '../../frameworks/react-vite/dist';

Expand Down Expand Up @@ -65,7 +64,6 @@ const config: StorybookConfig = {
...viteConfig,
plugins: [
...(viteConfig.plugins || []),
csfPlugin({}),
configType === 'PRODUCTION' ? pluginTurbosnap({ rootDir: viteConfig.root || '' }) : [],
],
optimizeDeps: { ...viteConfig.optimizeDeps, force: true },
Expand Down
2 changes: 1 addition & 1 deletion code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5873,11 +5873,11 @@ __metadata:
"@joshwooding/vite-plugin-react-docgen-typescript": 0.0.5
"@storybook/client-logger": 7.0.0-alpha.62
"@storybook/core-common": 7.0.0-alpha.62
"@storybook/csf-plugin": 7.0.0-alpha.62
"@storybook/mdx2-csf": next
"@storybook/node-logger": 7.0.0-alpha.62
"@storybook/preview": 7.0.0-alpha.62
"@storybook/preview-api": 7.0.0-alpha.62
"@storybook/source-loader": 7.0.0-alpha.62
"@storybook/types": 7.0.0-alpha.62
"@types/express": ^4.17.13
"@types/node": ^16.0.0
Expand Down