-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RNW-Vite: Add built-in Flow support #29756
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// @ts-expect-error FIXME | ||
import { viteFinal as reactViteFinal } from '@storybook/react-vite/preset'; | ||
|
||
import { esbuildFlowPlugin, flowPlugin } from '@bunchtogether/vite-plugin-flow'; | ||
import react from '@vitejs/plugin-react'; | ||
import type { PluginOption } from 'vite'; | ||
import type { InlineConfig, PluginOption } from 'vite'; | ||
|
||
import type { FrameworkOptions, StorybookConfig } from './types'; | ||
|
||
|
@@ -61,13 +62,19 @@ export function reactNativeWeb(): PluginOption { | |
} | ||
|
||
export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) => { | ||
const { mergeConfig } = await import('vite'); | ||
|
||
const { pluginReactOptions = {} } = | ||
await options.presets.apply<FrameworkOptions>('frameworkOptions'); | ||
|
||
const reactConfig = await reactViteFinal(config, options); | ||
|
||
const { plugins = [] } = reactConfig; | ||
|
||
plugins.unshift( | ||
flowPlugin({ | ||
exclude: [], | ||
}), | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Empty exclude array may cause Flow to process all files. Consider adding appropriate exclusions for node_modules and build artifacts |
||
react({ | ||
babel: { | ||
babelrc: false, | ||
|
@@ -77,9 +84,16 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) = | |
...pluginReactOptions, | ||
}) | ||
); | ||
|
||
plugins.push(reactNativeWeb()); | ||
|
||
return reactConfig; | ||
return mergeConfig(reactConfig, { | ||
optimizeDeps: { | ||
esbuildOptions: { | ||
plugins: [esbuildFlowPlugin(new RegExp(/\.(flow|jsx?)$/), (_path: string) => 'jsx')], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Regular expression should be anchored with ^ and $ to prevent partial matches in file paths |
||
}, | ||
}, | ||
} satisfies InlineConfig); | ||
}; | ||
|
||
export const core = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@bunchtogether/vite-plugin-flow'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Fix the underlying type error instead of using @ts-expect-error