|
| 1 | +import type { StorybookConfig } from '@storybook/react-webpack5'; |
| 2 | +import type { Configuration } from 'webpack'; |
| 3 | + |
1 | 4 | /**
|
2 | 5 | * Although `--static-dir` is marked as deprecated. The The Chromatic CLI
|
3 | 6 | * currently pulls the staticDir from the build script, but does not support
|
|
6 | 9 | * We should refrain from using the staticDirs option in this configuration until
|
7 | 10 | * https://github.com/chromaui/chromatic-cli/issues/462 is resolved.
|
8 | 11 | */
|
9 |
| -module.exports = { |
| 12 | +const config: StorybookConfig = { |
10 | 13 | stories: [
|
11 | 14 | './components/**/*.stories.mdx',
|
12 | 15 | './components/**/*.stories.@(js|jsx|ts|tsx)',
|
@@ -70,4 +73,47 @@ module.exports = {
|
70 | 73 | plugins: [],
|
71 | 74 | };
|
72 | 75 | },
|
| 76 | + webpackFinal(config, { configType }) { |
| 77 | + if (configType === 'DEVELOPMENT') { |
| 78 | + updateCSSLoaderPlugin(config); |
| 79 | + } |
| 80 | + return config; |
| 81 | + }, |
73 | 82 | };
|
| 83 | + |
| 84 | +/** |
| 85 | + * Updates the `css-loader` webpack plugin to make class names human readable. |
| 86 | + * |
| 87 | + * NOTE: This should only be used for local development. |
| 88 | + */ |
| 89 | +function updateCSSLoaderPlugin(config: Configuration): Configuration { |
| 90 | + config.module?.rules?.forEach((rule) => { |
| 91 | + if (rule && typeof rule === 'object' && Array.isArray(rule.use)) { |
| 92 | + const isRuleForCSS = rule.test?.toString() === '/\\.css$/'; |
| 93 | + if (isRuleForCSS) { |
| 94 | + rule.use.forEach((ruleSetRule) => { |
| 95 | + if ( |
| 96 | + typeof ruleSetRule === 'object' && |
| 97 | + ruleSetRule?.loader?.includes('node_modules/css-loader') |
| 98 | + ) { |
| 99 | + ruleSetRule.options = { |
| 100 | + // @ts-expect-error css-loader doesn't accept "string" options |
| 101 | + // and will either be an object or undefined |
| 102 | + ...ruleSetRule.options, |
| 103 | + modules: { |
| 104 | + // @ts-expect-error css-loader doesn't accept "string" options |
| 105 | + // and will either be an object or undefined |
| 106 | + ...ruleSetRule.options?.modules, |
| 107 | + localIdentName: '[name]__[local]--[hash:base64:5]', |
| 108 | + }, |
| 109 | + }; |
| 110 | + } |
| 111 | + }); |
| 112 | + } |
| 113 | + } |
| 114 | + }); |
| 115 | + |
| 116 | + return config; |
| 117 | +} |
| 118 | + |
| 119 | +export default config; |
0 commit comments