@@ -4,26 +4,21 @@ const path = require("path");
44module . exports = {
55 stories : [ "../src/**/*.stories.tsx" ] ,
66 addons : [
7- "@storybook/addon-actions/register " ,
8- "@storybook/addon-viewport/register " ,
7+ "@storybook/addon-essentials " ,
8+ "@storybook/addon-interactions " ,
99 ] ,
10+ // Enable the Storybook Interactions debugger
11+ // Docs: https://storybook.js.org/addons/@storybook /addon-interactions
12+ features : {
13+ interactionsDebugger : true ,
14+ } ,
15+ // Configure Storybook to use Webpack@5.x
16+ // Docs: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5
17+ core : {
18+ builder : "webpack5" ,
19+ } ,
1020 webpackFinal : async ( config ) => {
11- config . module . rules . push ( {
12- exclude : / n o d e _ m o d u l e s / ,
13- test : / \. s c s s $ / ,
14- use : [
15- {
16- loader : "style-loader" , // Creates style nodes from JS strings
17- } ,
18- {
19- loader : "css-loader" , // Translates CSS into CommonJS
20- } ,
21- {
22- loader : "sass-loader" , // Compiles Sass to CSS
23- } ,
24- ] ,
25- } ) ;
26-
21+ // Setup @src path resolution for TypeScript files
2722 config . resolve = {
2823 ...config . resolve ,
2924 extensions : [ ".ts" , ".tsx" , ".js" ] ,
@@ -32,6 +27,7 @@ module.exports = {
3227 } ,
3328 } ;
3429
30+ // Setup module replacement for mocked webextension-polyfill
3531 config . plugins = [
3632 ...config . plugins ,
3733 new webpack . NormalModuleReplacementPlugin (
@@ -57,6 +53,42 @@ module.exports = {
5753 ) ,
5854 ] ;
5955
56+ // Remove the default .css webpack module rule
57+ // This is necessary because we use both global CSS and CSS modules
58+ // in the extension and in Storybook
59+ config . module . rules = config . module . rules . filter ( ( r ) => {
60+ if ( ".css" . match ( r . test ) ) {
61+ return false ;
62+ }
63+ return true
64+ } )
65+
66+ // Treat src/css/app.css as a global stylesheet
67+ config . module . rules . push ( {
68+ test : / \a p p .c s s $ / ,
69+ use : [
70+ "style-loader" ,
71+ "css-loader" ,
72+ "postcss-loader" ,
73+ ] ,
74+ } )
75+
76+ // Load .module.css files as CSS modules
77+ config . module . rules . push ( {
78+ test : / \. m o d u l e .c s s $ / ,
79+ use : [
80+ "style-loader" ,
81+ {
82+ loader : "css-loader" ,
83+ options : {
84+ modules : true ,
85+ } ,
86+ } ,
87+ "postcss-loader" ,
88+ ] ,
89+ } )
90+
91+ // Return the final Webpack configuration
6092 return config ;
6193 } ,
6294} ;
0 commit comments