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

[Bug] Vitest plugin does not detect custom vite config paths #29777

Open
Tracked by #29770 ...
vanessayuenn opened this issue Dec 2, 2024 · 1 comment
Open
Tracked by #29770 ...

[Bug] Vitest plugin does not detect custom vite config paths #29777

vanessayuenn opened this issue Dec 2, 2024 · 1 comment

Comments

@vanessayuenn
Copy link
Contributor

Storybook, by default, loads a vite.config file in the project root. The same goes for Vitest. However, users can customize the vite config path like so:

// .storybook/main.js
export default {
  core: {
    builder: {
      name: '@storybook/builder-vite',
      options: {
        viteConfigPath: '.storybook/vite.config.ts',
      },
    },
  },
};

Vitest will not know about this, unless users manually load such vite config file in their vitest config file like so:

// vitest.config.ts
import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
	{ extends: '.storybook/vite.config.ts', plugins: [ storybookTest() ] ... }
])

Some people have a vite config file for their app and another for Storybook. The sb add command won't detect a vite config file in the Storybook dir (though we could), so it can end up referring to the wrong config file when setting things up.

💡 Solutions/Action items:

  • We can start checking the vite config file from the storybook configDir first
  • We should make this clear in our docs, if it isn't already
@ndelangen
Copy link
Member

The code for this, exists here:

const { viteConfigPath } = await getBuilderOptions<BuilderOptions>(options);
const projectRoot = resolve(options.configDir, '..');
// I destructure away the `build` property from the user's config object
// I do this because I can contain config that breaks storybook, such as we had in a lit project.
// If the user needs to configure the `build` they need to do so in the viteFinal function in main.js.
const { config: { build: buildProperty = undefined, ...userConfig } = {} } =
(await loadConfigFromFile(configEnv, viteConfigPath, projectRoot)) ?? {};

If this code was defined in a preset property viteFinal instead, this would be automatically compatible, and it would make the vite builder less custom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants