@@ -9,30 +9,51 @@ const config: StorybookConfig = {
99 '@storybook/addon-links' ,
1010 '@storybook/addon-essentials' ,
1111 '@storybook/addon-interactions' ,
12- '@storybook/addon-styling-webpack' ,
13- '@storybook/preset-scss'
12+ '@storybook/preset-scss' ,
1413 ] ,
1514 framework : {
1615 name : '@storybook/react-webpack5' ,
1716 options : {
1817 strictMode : true ,
1918 } ,
2019 } ,
20+ // Match the automatic JSX runtime used by tsconfig ("jsx": "react-jsx") so
21+ // story files don't need an explicit `import React`.
22+ swc : ( swcConfig ) => ( {
23+ ...swcConfig ,
24+ jsc : {
25+ ...swcConfig . jsc ,
26+ transform : {
27+ ...swcConfig . jsc ?. transform ,
28+ react : {
29+ ...swcConfig . jsc ?. transform ?. react ,
30+ runtime : 'automatic' ,
31+ } ,
32+ } ,
33+ } ,
34+ } ) ,
2135 webpackFinal : async ( currentConfig : WebpackConfiguration , { configType } ) => {
2236 // get index of css rule
2337 const ruleCssIndex = currentConfig . module . rules . findIndex (
24- ( rule ) => rule . test ?. toString ( ) === " /\\.css$/"
38+ ( rule ) => rule . test ?. toString ( ) === ' /\\.css$/'
2539 ) ;
2640
2741 // map over the 'use' array of the css rule and set the 'module' option to true
2842 currentConfig . module . rules [ ruleCssIndex ] . use . map ( ( item ) => {
29- if ( item . loader && item . loader . includes ( " /css-loader/" ) ) {
43+ if ( item . loader && item . loader . includes ( ' /css-loader/' ) ) {
3044 item . options . modules = {
31- mode : "local" ,
45+ // The library ships default.css as a plain global stylesheet
46+ // (consumers import it directly), so its class names must NOT be
47+ // scoped/hashed or component className strings won't match. Keep
48+ // everything else as local CSS modules.
49+ mode : ( resourcePath : string ) =>
50+ resourcePath . replace ( / \\ / g, '/' ) . endsWith ( 'styles/default.css' )
51+ ? 'global'
52+ : 'local' ,
3253 localIdentName :
33- configType === " PRODUCTION"
34- ? " [local]__[hash:base64:5]"
35- : " [name]__[local]__[hash:base64:5]" ,
54+ configType === ' PRODUCTION'
55+ ? ' [local]__[hash:base64:5]'
56+ : ' [name]__[local]__[hash:base64:5]' ,
3657 } ;
3758 }
3859
0 commit comments