|
| 1 | +import type { StorybookConfig } from '@storybook/react-webpack5'; |
| 2 | +import type { WebpackConfiguration } from '@storybook/core-webpack'; |
| 3 | + |
| 4 | +const config: StorybookConfig = { |
| 5 | + stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], |
| 6 | + addons: [ |
| 7 | + '@storybook/addon-webpack5-compiler-swc', |
| 8 | + '@storybook/addon-onboarding', |
| 9 | + '@storybook/addon-links', |
| 10 | + '@storybook/addon-essentials', |
| 11 | + '@storybook/addon-interactions', |
| 12 | + '@storybook/addon-styling-webpack', |
| 13 | + '@storybook/preset-scss' |
| 14 | + ], |
| 15 | + framework: { |
| 16 | + name: '@storybook/react-webpack5', |
| 17 | + options: { |
| 18 | + strictMode: true, |
| 19 | + }, |
| 20 | + }, |
| 21 | + webpackFinal: async (currentConfig: WebpackConfiguration, { configType }) => { |
| 22 | + // get index of css rule |
| 23 | + const ruleCssIndex = currentConfig.module.rules.findIndex( |
| 24 | + (rule) => rule.test?.toString() === "/\\.css$/" |
| 25 | + ); |
| 26 | + |
| 27 | + // map over the 'use' array of the css rule and set the 'module' option to true |
| 28 | + currentConfig.module.rules[ruleCssIndex].use.map((item) => { |
| 29 | + if (item.loader && item.loader.includes("/css-loader/")) { |
| 30 | + item.options.modules = { |
| 31 | + mode: "local", |
| 32 | + localIdentName: |
| 33 | + configType === "PRODUCTION" |
| 34 | + ? "[local]__[hash:base64:5]" |
| 35 | + : "[name]__[local]__[hash:base64:5]", |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + return item; |
| 40 | + }); |
| 41 | + |
| 42 | + return currentConfig; |
| 43 | + }, |
| 44 | +}; |
| 45 | +export default config; |
0 commit comments