Skip to content

Commit e70e337

Browse files
fix(qwik-nx): override qwikVite plugin for storybook (#127)
1 parent e07e0ba commit e70e337

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed
Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
import type { PluginOption, UserConfig } from 'vite';
2+
import {
3+
type QwikVitePluginOptions,
4+
qwikVite,
5+
} from '@builder.io/qwik/optimizer';
26

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 {
516
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+
});
1534
return updated;
1635
}

0 commit comments

Comments
 (0)