|
1 | 1 | import type { PluginOption, UserConfig } from 'vite';
|
| 2 | +import { |
| 3 | + type QwikVitePluginOptions, |
| 4 | + qwikVite, |
| 5 | +} from '@builder.io/qwik/optimizer'; |
2 | 6 |
|
3 |
| -/** Updates config for the storybook */ |
4 |
| -export function withNx(config: UserConfig): UserConfig { |
| 7 | +/** |
| 8 | + * Updates config for the storybook |
| 9 | + * @param config vite configuration to be updated for storybook |
| 10 | + * @param qwikViteOpts options for the `qwikVite` plugin that is being overridden in this utility |
| 11 | + */ |
| 12 | +export function withNx( |
| 13 | + config: UserConfig, |
| 14 | + qwikViteOpts?: QwikVitePluginOptions |
| 15 | +): UserConfig { |
5 | 16 | const updated = { ...config };
|
6 |
| - // logic below has been copied from "storybook-framework-qwik" plugin |
7 |
| - // it doesn't work out of the box for Nx applications because base config is not |
8 |
| - // Qwik-city plugin may be used in apps, but it has mdx stuff that conflicts with Storybook mdx |
9 |
| - // we'll try to only remove the transform code (where the mdx stuff is), and keep everything else. |
10 |
| - updated.plugins = updated.plugins?.map((plugin: PluginOption) => |
11 |
| - (plugin as any)?.name === 'vite-plugin-qwik-city' |
12 |
| - ? ({ ...plugin, transform: () => null } as PluginOption) |
13 |
| - : plugin |
14 |
| - ); |
| 17 | + updated.plugins = updated.plugins?.map((plugin: PluginOption) => { |
| 18 | + switch ((plugin as any)?.name) { |
| 19 | + case 'vite-plugin-qwik': |
| 20 | + // as of now there's no way of extending qwikVite with overridden output paths, thus have to override to completely |
| 21 | + return qwikVite(qwikViteOpts); |
| 22 | + |
| 23 | + case 'vite-plugin-qwik-city': |
| 24 | + // logic below has been copied from "storybook-framework-qwik" plugin |
| 25 | + // it doesn't work out of the box for Nx applications because base config is not included by storybook if it's not in the root cwd |
| 26 | + // Qwik-city plugin may be used in apps, but it has mdx stuff that conflicts with Storybook mdx |
| 27 | + // we'll try to only remove the transform code (where the mdx stuff is), and keep everything else. |
| 28 | + return { ...plugin, transform: () => null } as PluginOption; |
| 29 | + |
| 30 | + default: |
| 31 | + return plugin; |
| 32 | + } |
| 33 | + }); |
15 | 34 | return updated;
|
16 | 35 | }
|
0 commit comments