|
62 | 62 |
|
63 | 63 | 👉 More information on Component-Level CSS in the [official doc](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css)
|
64 | 64 |
|
| 65 | +## For Storybook |
| 66 | + |
| 67 | +1. Remove `.storybook/.babelrc` and `.storybook/webpack.config.js` |
| 68 | +2. Update your `.storybook/main.js` with something like: |
| 69 | + ```js |
| 70 | + const path = require('path'); |
| 71 | + |
| 72 | + module.exports = { |
| 73 | + "stories": [ |
| 74 | + "../src/**/*.stories.mdx", |
| 75 | + "../src/**/*.stories.@(js|jsx|ts|tsx)", |
| 76 | + ], |
| 77 | + "addons": [ |
| 78 | + "@storybook/addon-docs", |
| 79 | + "@storybook/addon-links", |
| 80 | + "@storybook/addon-essentials", |
| 81 | + { |
| 82 | + name: '@storybook/addon-postcss', |
| 83 | + options: { |
| 84 | + postcssLoaderOptions: { |
| 85 | + implementation: require('postcss'), |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + 'storybook-css-modules-preset', |
| 90 | + // 'storybook-addon-next-router', |
| 91 | + ], |
| 92 | + // staticDirs: ['../public'], |
| 93 | + // typescript: { reactDocgen: 'react-docgen-typescript' }, |
| 94 | + typescript: { reactDocgen: false }, |
| 95 | + framework: "@storybook/react", |
| 96 | + core: { |
| 97 | + builder: "webpack5", |
| 98 | + }, |
| 99 | + webpackFinal: async (config, { configType }) => { |
| 100 | + // Needed because of an issue with the latest version in framer-motion |
| 101 | + // https://github.com/framer/motion/issues/1307 |
| 102 | + // config.module.rules.push({ |
| 103 | + // type: "javascript/auto", |
| 104 | + // test: /\.mjs$/, |
| 105 | + // include: /node_modules/, |
| 106 | + // }); |
| 107 | + |
| 108 | + config.resolve = { |
| 109 | + ...config.resolve, |
| 110 | + modules: [path.resolve(__dirname, '../src'), 'node_modules'], |
| 111 | + }; |
| 112 | + |
| 113 | + const fileLoaderRule = config.module.rules.find( |
| 114 | + (rule) => !Array.isArray(rule.test) && rule.test.test(".svg"), |
| 115 | + ); |
| 116 | + fileLoaderRule.exclude = /\.svg$/; |
| 117 | + config.module.rules.push({ |
| 118 | + test: /\.svg$/, |
| 119 | + use: ['@svgr/webpack'], |
| 120 | + }); |
| 121 | + |
| 122 | + return config; |
| 123 | + }, |
| 124 | + } |
| 125 | + ``` |
| 126 | + 3. Add `import "../src/styles/globals.css";` in your `.storybook/preview.js` |
| 127 | + |
65 | 128 |
|
66 | 129 |
|
0 commit comments