Side effects raised in the initial question:
vite-plugin-dts
breaks Storybook production build.To correct this behavior, define the declarationDir
in your tsconfig.json file.
{
"compilerOptions": {
"declaration": true,
"declarationDir": "./build",
},
}
See next step for removing dts
from the Storybook build step.
you can
viteFinal(config){ config.plugins.shift(); return config; }
as far as I undestood
//.storybook/maint.ts`
const config: StorybookConfig = {
// ...
async viteFinal(config) {
const { mergeConfig } = await import('vite');
/**
* `storybook build` does not reconcile the path correctly for the `vite:dts` plugin and causes the
* build to fail. By removing the plugin, storybook will successfully build.
*/
const dtsIndex = config.plugins?.findIndex((plugin) => {
if (plugin && typeof plugin === 'object' && 'name' in plugin && plugin.name === 'vite:dts') {
return true;
}
return false;
});
// Remove `vite:dts` plugin from config.plugins array using the index provided in `dtsIndex`.
if (dtsIndex !== undefined && dtsIndex !== -1) {
config.plugins?.splice(dtsIndex, 1);
}
return mergeConfig(config, {
resolve: {
...config.resolve,
},
});
},
};
[1]: https://stackoverflow.com/questions/76017338/prevent-creating-definition-files-d-ts-onstorybook-build-vite-react-library-p#comment134090392_76017338