Skip to content

Commit

Permalink
refactor: ♻️ Update Babel configuration for Storybook compatibility a…
Browse files Browse the repository at this point in the history
…nd make Storybook work with webpack
  • Loading branch information
singhAmandeep007 committed Oct 1, 2024
1 parent 8699292 commit 14c15aa
Show file tree
Hide file tree
Showing 11 changed files with 1,503 additions and 3,444 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"presets": ["react-app"],
"presets": [
"react-app",
// NOTE: explicitly defined to work with storybook
// transforming JSX syntax into regular JavaScript
["@babel/preset-react", { "runtime": "automatic" }]
],
"env": {
"development": {
"plugins": [
Expand Down
54 changes: 50 additions & 4 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
import type { StorybookConfig } from "@storybook/react-webpack5";

import configFactory from "../config/webpack.config";

import { mergeUniqueArrays } from "../utils";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],

webpackFinal: async (config, { configType }) => {
const customWebpackConfig = configFactory(configType?.toLocaleLowerCase() || "development");

if (configType === "DEVELOPMENT") {
// Modify config for development
}
if (configType === "PRODUCTION") {
// Modify config for production
}

if (config.resolve) {
if (config.resolve.modules)
config.resolve.modules = mergeUniqueArrays(config.resolve.modules, customWebpackConfig.resolve.modules);

if (config.resolve.extensions)
config.resolve.extensions = mergeUniqueArrays(
config.resolve.extensions,
customWebpackConfig.resolve.extensions
);
}

if (config.module?.rules) {
config.module.rules.push({
test: /\.css$/,
use: [
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require("tailwindcss")],
},
},
},
],
});
}

return config;
},
addons: [
"@storybook/addon-webpack5-compiler-swc",
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
"@storybook/addon-styling-webpack",
"@storybook/addon-themes",
"@storybook/addon-a11y",
"@storybook/addon-webpack5-compiler-babel",
],
framework: {
name: "@storybook/react-webpack5",
options: {},
},
docs: {
autodocs: "tag",
},
staticDirs: ["../public"],
docs: {},
};
export default config;
17 changes: 17 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Preview } from "@storybook/react";

import { withThemeByClassName } from "@storybook/addon-themes";

import "../src/index.css";

const preview: Preview = {
parameters: {
controls: {
Expand All @@ -9,6 +13,19 @@ const preview: Preview = {
},
},
},
tags: ["autodocs"],
};

export default preview;

/* snipped for brevity */
export const decorators = [
withThemeByClassName({
themes: {
// nameOfTheme: 'classNameForTheme',
light: "light",
dark: "dark",
},
defaultTheme: "light",
}),
];
Loading

0 comments on commit 14c15aa

Please sign in to comment.