Skip to content

Commit 87f1ff0

Browse files
committed
🤖 Fix Chromatic emotion/styled bundling issue
Configure Vite and TypeScript for proper emotion support: - Add jsxImportSource to tsconfig.json - Configure @vitejs/plugin-react with emotion babel plugin - Add viteFinal to Storybook main.ts with emotion optimizeDeps - Add @emotion/babel-plugin as dev dependency This ensures emotion/styled components are properly bundled in Chromatic's production build environment. _Generated with `cmux`_
1 parent 76228d9 commit 87f1ff0

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

.storybook/main.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { StorybookConfig } from '@storybook/react-vite';
2+
import type { UserConfig } from 'vite';
23

34
const config: StorybookConfig = {
45
"stories": [
@@ -15,6 +16,28 @@ const config: StorybookConfig = {
1516
"framework": {
1617
"name": "@storybook/react-vite",
1718
"options": {}
18-
}
19+
},
20+
async viteFinal(config: UserConfig) {
21+
return {
22+
...config,
23+
plugins: config.plugins,
24+
optimizeDeps: {
25+
...config.optimizeDeps,
26+
include: [
27+
...(config.optimizeDeps?.include || []),
28+
'@emotion/react',
29+
'@emotion/styled',
30+
'@emotion/cache',
31+
],
32+
},
33+
build: {
34+
...config.build,
35+
commonjsOptions: {
36+
...config.build?.commonjsOptions,
37+
include: [/node_modules/],
38+
},
39+
},
40+
};
41+
},
1942
};
2043
export default config;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
},
6464
"devDependencies": {
6565
"@chromatic-com/storybook": "^4.1.1",
66+
"@emotion/babel-plugin": "^11.13.5",
6667
"@eslint/js": "^9.36.0",
6768
"@storybook/addon-a11y": "^9.1.10",
6869
"@storybook/addon-docs": "^9.1.10",

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"module": "ESNext",
66
"moduleResolution": "node",
77
"jsx": "react-jsx",
8+
"jsxImportSource": "@emotion/react",
89
"strict": true,
910
"esModuleInterop": true,
1011
"skipLibCheck": true,

vite.config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ import { fileURLToPath } from "url";
88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
99

1010
export default defineConfig({
11-
plugins: [react(), wasm(), topLevelAwait()],
11+
plugins: [
12+
react({
13+
jsxImportSource: '@emotion/react',
14+
babel: {
15+
plugins: ['@emotion/babel-plugin'],
16+
},
17+
}),
18+
wasm(),
19+
topLevelAwait(),
20+
],
1221
resolve: {
1322
alias: {
1423
"@": path.resolve(__dirname, "./src"),

0 commit comments

Comments
 (0)