import { stringifyEnvs } from '@storybook/core-common' ; import type { EnvsRaw } from './types' ; import type { UserConfig } from 'vite' ; const allowedEnvVariables = [ 'STORYBOOK' , 'BASE_URL' , 'MODE' , 'DEV' , 'PROD' , 'SSR' , ] ; export const allowedEnvPrefix = [ 'VITE_' , 'STORYBOOK_' ] ; /**
 * Customized version of stringifyProcessEnvs from @storybook/core-common which
 * uses import.meta.env instead of process.env and checks for allowed variables.
 */ export function stringifyProcessEnvs ( raw , envPrefix ) { const updatedRaw = { } ; const envs = Object . entries ( raw ) . reduce ( ( acc , [ key , value ] ) => { if ( allowedEnvVariables . includes ( key ) || ( Array . isArray ( envPrefix ) && ! ! envPrefix . find ( ( prefix ) => key . startsWith ( prefix ) ) ) || ( typeof envPrefix === 'string' && key . startsWith ( envPrefix ) ) ) { acc [ `import.meta.env.${ key }` ] = JSON . stringify ( value ) ; updatedRaw [ key ] = value ; } return acc ; } , { 'process.env.XSTORYBOOK_EXAMPLE_APP' : '""' , } ) ; envs [ 'import.meta.env' ] = JSON . stringify ( stringifyEnvs ( updatedRaw ) ) ; return envs ; }