Skip to content

Commit

Permalink
Merge pull request #29710 from storybookjs/yann/support-vite-6
Browse files Browse the repository at this point in the history
Frameworks: Add Vite 6 support
(cherry picked from commit 8e5be14)
  • Loading branch information
yannbf committed Nov 28, 2024
1 parent 8316d7d commit 9c90a52
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
11 changes: 10 additions & 1 deletion code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,18 @@ export const storybookTest = (options?: UserOptions): Plugin => {
config.test.browser.screenshotFailures ??= false;
}

// copying straight from https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts#L60
// to avoid having to maintain Vite as a dependency just for this
const viteDefaultClientConditions = ['module', 'browser', 'development|production'];

config.resolve ??= {};
config.resolve.conditions ??= [];
config.resolve.conditions.push('storybook', 'stories', 'test');
config.resolve.conditions.push(
'storybook',
'stories',
'test',
...viteDefaultClientConditions
);

config.test.setupFiles ??= [];
if (typeof config.test.setupFiles === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"peerDependencies": {
"storybook": "workspace:^",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 1 addition & 0 deletions code/builders/builder-vite/src/vite-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { commonConfig } from './vite-config';
vi.mock('vite', async (importOriginal) => ({
...(await importOriginal<typeof import('vite')>()),
loadConfigFromFile: vi.fn(async () => ({})),
defaultClientConditions: undefined,
}));
const loadConfigFromFileMock = vi.mocked(loadConfigFromFile);

Expand Down
6 changes: 4 additions & 2 deletions code/builders/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export async function commonConfig(
_type: PluginConfigType
): Promise<ViteInlineConfig> {
const configEnv = _type === 'development' ? configEnvServe : configEnvBuild;
const { loadConfigFromFile, mergeConfig } = await import('vite');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this property only exists in Vite 6
const { loadConfigFromFile, mergeConfig, defaultClientConditions = [] } = await import('vite');

const { viteConfigPath } = await getBuilderOptions<BuilderOptions>(options);

Expand All @@ -67,7 +69,7 @@ export async function commonConfig(
base: './',
plugins: await pluginConfig(options),
resolve: {
conditions: ['storybook', 'stories', 'test'],
conditions: ['storybook', 'stories', 'test', ...defaultClientConditions],
preserveSymlinks: isPreservingSymlinks(),
alias: {
assert: require.resolve('browser-assert'),
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/experimental-nextjs-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
"storybook": "workspace:^",
"vite": "^5.0.0"
"vite": "^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"typescript": {
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
"storybook": "workspace:^",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@sveltejs/vite-plugin-svelte": "^2.0.0 || ^3.0.0 || ^4.0.0",
"storybook": "workspace:^",
"svelte": "^4.0.0 || ^5.0.0",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"peerDependencies": {
"storybook": "workspace:^",
"svelte": "^4.0.0 || ^5.0.0",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/vue3-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"peerDependencies": {
"storybook": "workspace:^",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
12 changes: 6 additions & 6 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5997,7 +5997,7 @@ __metadata:
vite: "npm:^4.0.4"
peerDependencies:
storybook: "workspace:^"
vite: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0 || ^6.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -6483,7 +6483,7 @@ __metadata:
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta
storybook: "workspace:^"
vite: ^5.0.0
vite: ^5.0.0 || ^6.0.0
dependenciesMeta:
sharp:
optional: true
Expand Down Expand Up @@ -6940,7 +6940,7 @@ __metadata:
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta
storybook: "workspace:^"
vite: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0 || ^6.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -7237,7 +7237,7 @@ __metadata:
"@sveltejs/vite-plugin-svelte": ^2.0.0 || ^3.0.0 || ^4.0.0
storybook: "workspace:^"
svelte: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0 || ^6.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -7296,7 +7296,7 @@ __metadata:
peerDependencies:
storybook: "workspace:^"
svelte: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0 || ^6.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -7391,7 +7391,7 @@ __metadata:
vue-docgen-api: "npm:^4.75.1"
peerDependencies:
storybook: "workspace:^"
vite: ^4.0.0 || ^5.0.0
vite: ^4.0.0 || ^5.0.0 || ^6.0.0
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 9c90a52

Please sign in to comment.