Skip to content

Instantly share code, notes, and snippets.

@dannyhw
Created August 21, 2025 15:33
Show Gist options
  • Save dannyhw/544f1801673de515f2570fb196b70843 to your computer and use it in GitHub Desktop.
Save dannyhw/544f1801673de515f2570fb196b70843 to your computer and use it in GitHub Desktop.
make EXPO_PUBLIC accessible to storybook
import { StorybookConfig } from "@storybook/react-native-web-vite";
import { InlineConfig, mergeConfig } from "vite";
const main: StorybookConfig = {
stories: ["../components/**/*.stories.@(js|jsx|ts|tsx)"],
addons: ["@storybook/addon-docs", "@chromatic-com/storybook"],
framework: {
name: "@storybook/react-native-web-vite",
options: {},
},
viteFinal: (config) => {
return mergeConfig(config, {
define: Object.entries(process.env).reduce((acc, [key, value]) => {
if (key.startsWith("EXPO_PUBLIC_")) {
acc[`process.env.${key}`] = JSON.stringify(value);
}
return acc;
}, {} as Record<string, string>),
} satisfies InlineConfig);
},
// env: ,
};
export default main;
@dannyhw
Copy link
Author

dannyhw commented Aug 21, 2025

This will take EXPO_PUBLIC_ env variables and include them in the vite environment as process.env.EXPO_PUBLIC_[name-of-env]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment