|
1 | 1 | const rootMain = require('../../../../.storybook/main');
|
| 2 | +const { |
| 3 | + addons: rootAddons, |
| 4 | + stories: rootStories, |
| 5 | + webpackFinal: rootWebpackFinal, |
| 6 | +} = rootMain; |
2 | 7 |
|
3 |
| -// Use the following syntax to add addons! |
4 |
| -//rootMain.addons.push(''); |
| 8 | +module.exports = { |
| 9 | + ...rootMain, |
5 | 10 |
|
6 |
| -rootMain.stories.push( |
7 |
| - ...['../src/lib/**/*.stories.mdx', '../src/lib/**/*.stories.@(js|jsx|ts|tsx)'] |
8 |
| -); |
| 11 | + addons: [...rootAddons], |
9 | 12 |
|
10 |
| -module.exports = rootMain; |
| 13 | + stories: [ |
| 14 | + ...rootStories, |
| 15 | + '../src/lib/**/*.stories.mdx', |
| 16 | + '../src/lib/**/*.stories.@(js|jsx|ts|tsx)', |
| 17 | + ], |
| 18 | + |
| 19 | + webpackFinal: async (config) => { |
| 20 | + config = await rootWebpackFinal(config); |
| 21 | + |
| 22 | + // Found this here: https://github.com/nrwl/nx/issues/2859 |
| 23 | + // And copied the part of the solution that made it work |
| 24 | + |
| 25 | + const svgRuleIndex = config.module.rules.findIndex((rule) => { |
| 26 | + const { test } = rule; |
| 27 | + |
| 28 | + return test.toString().startsWith('/\\.(svg|ico'); |
| 29 | + }); |
| 30 | + |
| 31 | + config.module.rules[svgRuleIndex].test = |
| 32 | + /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/; |
| 33 | + |
| 34 | + config.module.rules.push( |
| 35 | + { |
| 36 | + test: /\.(png|jpe?g|gif|webp)$/, |
| 37 | + loader: require.resolve('url-loader'), |
| 38 | + options: { |
| 39 | + limit: 10000, // 10kB |
| 40 | + name: '[name].[hash:7].[ext]', |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + test: /\.svg$/, |
| 45 | + oneOf: [ |
| 46 | + // If coming from JS/TS file, then transform into React component using SVGR. |
| 47 | + { |
| 48 | + issuer: { |
| 49 | + test: /\.[jt]sx?$/, |
| 50 | + }, |
| 51 | + use: [ |
| 52 | + '@svgr/webpack?-svgo,+titleProp,+ref![path]', |
| 53 | + { |
| 54 | + loader: require.resolve('url-loader'), |
| 55 | + options: { |
| 56 | + limit: 10000, // 10kB |
| 57 | + name: '[name].[hash:7].[ext]', |
| 58 | + esModule: false, |
| 59 | + }, |
| 60 | + }, |
| 61 | + ], |
| 62 | + }, |
| 63 | + // Fallback to plain URL loader. |
| 64 | + { |
| 65 | + use: [ |
| 66 | + { |
| 67 | + loader: require.resolve('url-loader'), |
| 68 | + options: { |
| 69 | + limit: 10000, // 10kB |
| 70 | + name: '[name].[hash:7].[ext]', |
| 71 | + }, |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + ], |
| 76 | + } |
| 77 | + ); |
| 78 | + |
| 79 | + return config; |
| 80 | + }, |
| 81 | +}; |
0 commit comments