|
1 | 1 | /** @type { import('@storybook/svelte-vite').StorybookConfig } */ |
| 2 | +process.env.CHROMATIC_DISABLE = 'true'; |
| 3 | + |
2 | 4 | const config = { |
| 5 | + framework: '@storybook/svelte-vite', |
3 | 6 | stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|svelte)'], |
4 | 7 | addons: [ |
5 | 8 | '@storybook/addon-links', |
6 | | - '@storybook/addon-essentials', |
7 | | - '@storybook/addon-interactions', |
8 | | - '@storybook/addon-designs', |
| 9 | + '@storybook/addon-docs', |
| 10 | + '@storybook/addon-vitest', |
| 11 | + '@chromatic-com/storybook', |
| 12 | + '@storybook/addon-a11y', |
9 | 13 | ], |
10 | | - framework: { |
11 | | - name: '@storybook/svelte-vite', |
12 | | - options: {}, |
13 | | - }, |
14 | 14 | features: { |
15 | | - interactionsDebugger: true, |
| 15 | + interactions: true, |
16 | 16 | }, |
17 | 17 | docs: {}, |
18 | 18 | staticDirs: ['../src/public'], |
19 | 19 | async viteFinal(config, { configType }) { |
20 | 20 | const { mergeConfig } = await import('vite'); |
21 | | - |
22 | | - if (configType === 'DEVELOPMENT') { |
23 | | - // Your development configuration goes here |
24 | | - } |
| 21 | + |
25 | 22 | if (configType === 'PRODUCTION') { |
26 | | - // Your production configuration goes here. |
27 | | - config.plugins = config.plugins.filter(plugin => { |
28 | | - return plugin.name != 'postbuild-commands' |
29 | | - }) |
| 23 | + config.plugins = config.plugins.filter((plugin) => { |
| 24 | + return plugin.name != 'postbuild-commands'; |
| 25 | + }); |
30 | 26 | } |
31 | 27 | return mergeConfig(config, { |
32 | | - // Your environment configuration here |
| 28 | + //this plugin is a (hopefully) temporary workaround for storybook not picking up our local styles |
| 29 | + //we use an alias to reference bootstrap styles and they weren't getting picked up by storybook at all during prod build |
| 30 | + //if we only used storybook for dev, I would've never seen this issue, but chromatic builds for prod for our snapshots |
| 31 | + plugins: [ |
| 32 | + { |
| 33 | + name: 'inject-preview-css', |
| 34 | + enforce: 'post', |
| 35 | + generateBundle(options, bundle) { |
| 36 | + //find the style.css chunk |
| 37 | + const cssChunk = Object.values(bundle).find( |
| 38 | + (chunk) => chunk.type === 'asset' && chunk.name === 'style.css' |
| 39 | + ); |
| 40 | + |
| 41 | + if (cssChunk) { |
| 42 | + const iframeHtml = Object.values(bundle).find( |
| 43 | + (chunk) => chunk.type === 'asset' && chunk.fileName === 'iframe.html' |
| 44 | + ); |
| 45 | + |
| 46 | + if (iframeHtml) { |
| 47 | + iframeHtml.source = iframeHtml.source.replace( |
| 48 | + '</head>', |
| 49 | + ` <link rel="stylesheet" href="/${cssChunk.fileName}">\n</head>` |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + }, |
| 54 | + }, |
| 55 | + ], |
33 | 56 | build: { |
| 57 | + cssCodeSplit: false, |
34 | 58 | rollupOptions: { |
35 | | - external: [ |
36 | | - /^..\/fonts/, |
37 | | - /^\/common\/firebird/ |
38 | | - ] |
| 59 | + external: [/^..\/fonts/, /^\/common\/firebird/], |
39 | 60 | }, |
40 | 61 | }, |
41 | 62 | }); |
|
0 commit comments