Skip to content

Commit

Permalink
cleanup viteFinals
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Dec 20, 2024
1 parent 5bb9a7f commit e1cd01a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
39 changes: 18 additions & 21 deletions code/frameworks/react-native-web-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,25 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) =
const { pluginReactOptions = {} } =
await options.presets.apply<FrameworkOptions>('frameworkOptions');

const reactConfig = await reactViteFinal(config, options);
const { plugins = [], ...reactConfigWithoutPlugins } = await reactViteFinal(config, options);

const { plugins = [] } = reactConfig;

plugins.unshift(
tsconfigPaths(),
flowPlugin({
exclude: [/node_modules\/(?!react-native|@react-native)/],
}),
react({
babel: {
babelrc: false,
configFile: false,
},
jsxRuntime: 'automatic',
...pluginReactOptions,
})
);

plugins.push(reactNativeWeb());

return mergeConfig(reactConfig, {
return mergeConfig(reactConfigWithoutPlugins, {
plugins: [
tsconfigPaths(),
flowPlugin({
exclude: [/node_modules\/(?!react-native|@react-native)/],
}),
react({
babel: {
babelrc: false,
configFile: false,
},
jsxRuntime: 'automatic',
...pluginReactOptions,
}),
...plugins,
reactNativeWeb(),
],
optimizeDeps: {
esbuildOptions: {
plugins: [esbuildFlowPlugin(new RegExp(/\.(flow|jsx?)$/), (_path: string) => 'jsx')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Plugin } from 'vite';
const filename = __filename ?? fileURLToPath(import.meta.url);
const dir = dirname(filename);

export async function mockSveltekitStores() {
export function mockSveltekitStores() {
return {
name: 'storybook:sveltekit-mock-stores',
config: () => ({
Expand Down
25 changes: 12 additions & 13 deletions code/frameworks/sveltekit/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entry =
export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (config, options) => {
const baseConfig = await svelteViteFinal(config, options);

let { plugins = [] } = baseConfig;

// disable specific plugins that are not compatible with Storybook
plugins = (
await withoutVitePlugins(plugins, [
'vite-plugin-sveltekit-compile',
'vite-plugin-sveltekit-guard',
])
)
.concat(configOverrides())
.concat(await mockSveltekitStores());

return { ...baseConfig, plugins };
return {
...baseConfig,
plugins: [
// disable specific plugins that are not compatible with Storybook
...(await withoutVitePlugins(baseConfig.plugins ?? [], [
'vite-plugin-sveltekit-compile',
'vite-plugin-sveltekit-guard',
])),
configOverrides(),
mockSveltekitStores(),
],
};
};

0 comments on commit e1cd01a

Please sign in to comment.