Skip to content

Commit 578d88c

Browse files
committed
Update Storybook webpack configuration, preview.js
1 parent ff87772 commit 578d88c

File tree

2 files changed

+52
-46
lines changed

2 files changed

+52
-46
lines changed

.storybook/main.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@ const path = require("path");
44
module.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: /node_modules/,
13-
test: /\.scss$/,
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: /\app.css$/,
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: /\.module.css$/,
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
};

.storybook/preview.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,2 @@
1-
import {
2-
addParameters,
3-
addDecorator,
4-
INITIAL_VIEWPORTS,
5-
} from "@storybook/react";
6-
import { withConsole, setConsoleOptions } from "@storybook/addon-console";
7-
import { withInfo } from "@storybook/addon-info";
8-
9-
// Configure Viewports addon
10-
addParameters({
11-
viewport: {
12-
viewports: INITIAL_VIEWPORTS,
13-
defaultViewport: "someDefault",
14-
},
15-
});
16-
17-
// You'll start to receive all console messages, warnings, errors in your action logger panel - Everything except HMR logs.
18-
setConsoleOptions({
19-
panelExclude: [],
20-
});
21-
22-
// Setup StoryInfo addon
23-
addDecorator(withInfo);
24-
25-
// You'll receive console outputs as a console,
26-
// warn and error actions in the panel. You might want to know from
27-
// what stories they come. In this case, add withConsole decorator:
28-
addDecorator((storyFn, context) => withConsole()(storyFn)(context));
1+
// Import global app.css file
2+
import "../src/css/app.css";

0 commit comments

Comments
 (0)