-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Wrap vite-plugin-external in custom plugin and fix issues
- Loading branch information
Showing
3 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
code/lib/builder-vite/src/plugins/external-globals-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { globals } from '@storybook/preview/globals'; | ||
import type { Plugin } from 'vite'; | ||
import { viteExternalsPlugin } from 'vite-plugin-externals'; | ||
|
||
type ConfigHookFn = Extract< | ||
ReturnType<typeof viteExternalsPlugin>['config'], | ||
(...args: any[]) => any | ||
>; | ||
|
||
export async function externalsGlobalsPlugin() { | ||
const plugin = viteExternalsPlugin(globals, { useWindow: false }); | ||
return { | ||
...plugin, | ||
name: 'storybook:external-globals-plugin', | ||
// wrap config hook to fix issues from `vite-plugin-externals` | ||
async config(...configArgs) { | ||
const config = await (plugin.config as ConfigHookFn)(...configArgs); | ||
return { | ||
resolve: { | ||
alias: config?.resolve?.alias, | ||
}, | ||
}; | ||
}, | ||
} satisfies Plugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters