|
| 1 | +const excludedProps = new Set([ |
| 2 | + 'id', |
| 3 | + 'slot', |
| 4 | + 'onCopy', |
| 5 | + 'onCut', |
| 6 | + 'onPaste', |
| 7 | + 'onCompositionStart', |
| 8 | + 'onCompositionEnd', |
| 9 | + 'onCompositionUpdate', |
| 10 | + 'onSelect', |
| 11 | + 'onBeforeInput', |
| 12 | + 'onInput' |
| 13 | +]); |
| 14 | + |
| 15 | +import sharedArrayBufferPlugin from './shared-array-buffer-plugin'; |
| 16 | + |
| 17 | +/** @type { import('@storybook/react-vite').StorybookConfig } */ |
| 18 | +const config = { |
| 19 | + stories: [ |
| 20 | + "../stories/**/*.mdx", |
| 21 | + "../stories/**/Chat.stories.@(js|jsx|mjs|ts|tsx)", |
| 22 | + "../stories/**/ModelContextProtocol.stories.@(js|jsx|mjs|ts|tsx)", |
| 23 | + "../stories/WebContainer.stories.tsx", |
| 24 | + ], |
| 25 | + addons: [ |
| 26 | + "@storybook/addon-links", |
| 27 | + "@storybook/addon-essentials", |
| 28 | + "@storybook/addon-onboarding", |
| 29 | + "@storybook/addon-interactions", |
| 30 | + ], |
| 31 | + framework: { |
| 32 | + name: "@storybook/react-vite", |
| 33 | + options: { |
| 34 | + builder: { |
| 35 | + viteConfigPath: 'vite.config.js', |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + docs: { |
| 40 | + autodocs: "tag", |
| 41 | + }, |
| 42 | + typescript: { |
| 43 | + reactDocgen: 'react-docgen-typescript', |
| 44 | + reactDocgenTypescriptOptions: { |
| 45 | + shouldExtractLiteralValuesFromEnum: true, |
| 46 | + compilerOptions: { |
| 47 | + allowSyntheticDefaultImports: false, |
| 48 | + esModuleInterop: false, |
| 49 | + }, |
| 50 | + propFilter: (prop) => !prop.name.startsWith('aria-') && !excludedProps.has(prop.name), |
| 51 | + }, |
| 52 | + }, |
| 53 | + staticDirs: ['../public'], |
| 54 | + async viteFinal(config, { configType }) { |
| 55 | + // Add headers for SharedArrayBuffer support |
| 56 | + if (configType === 'DEVELOPMENT') { |
| 57 | + // Add server configuration |
| 58 | + config.server = config.server || {}; |
| 59 | + config.server.headers = { |
| 60 | + 'Cross-Origin-Opener-Policy': 'same-origin', |
| 61 | + 'Cross-Origin-Embedder-Policy': 'require-corp', |
| 62 | + }; |
| 63 | + } |
| 64 | + |
| 65 | + // For both DEVELOPMENT and PRODUCTION modes |
| 66 | + // Handle "use client" directives |
| 67 | + config.build = config.build || {}; |
| 68 | + config.build.rollupOptions = config.build.rollupOptions || {}; |
| 69 | + |
| 70 | + // Handle GitHub Pages deployment - add base path if needed |
| 71 | + if (configType === 'PRODUCTION') { |
| 72 | + // Check for GitHub Pages environment |
| 73 | + const isGitHubPages = process.env.GITHUB_ACTIONS === 'true'; |
| 74 | + |
| 75 | + if (isGitHubPages) { |
| 76 | + // Get repository name from GitHub context or use a fallback |
| 77 | + const repositoryName = process.env.GITHUB_REPOSITORY?.split('/')[1] || ''; |
| 78 | + |
| 79 | + if (repositoryName) { |
| 80 | + console.log(`GitHub Pages detected, setting base path to /${repositoryName}/`); |
| 81 | + config.base = `/${repositoryName}/`; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + // Add custom Rollup plugin to inject headers into HTML files |
| 87 | + config.plugins = config.plugins || []; |
| 88 | + |
| 89 | + // Add our SharedArrayBuffer plugin that works in both dev and production |
| 90 | + config.plugins.push(sharedArrayBufferPlugin()); |
| 91 | + |
| 92 | + // Ignore "use client" directive warnings |
| 93 | + config.build.rollupOptions.onwarn = (warning, defaultHandler) => { |
| 94 | + if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && |
| 95 | + warning.message.includes('"use client"')) { |
| 96 | + return; |
| 97 | + } |
| 98 | + if (defaultHandler) defaultHandler(warning); |
| 99 | + }; |
| 100 | + |
| 101 | + return config; |
| 102 | + }, |
| 103 | +}; |
| 104 | +export default config; |
0 commit comments