|
| 1 | +/* eslint-disable no-param-reassign */ |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +/** |
| 5 | + * @param {{ name: string; dirname: string; }} param0 Options |
| 6 | + * @returns {import('@storybook/react-webpack5').StorybookConfig} |
| 7 | + */ |
| 8 | +module.exports = ({ name, dirname }) => ({ |
| 9 | + stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], |
| 10 | + addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions', '@storybook/preset-scss', 'storybook-addon-swc', '@storybook/addon-mdx-gfm'], |
| 11 | + framework: { |
| 12 | + name: '@storybook/react-webpack5', |
| 13 | + options: { |
| 14 | + builder: { |
| 15 | + useSWC: true, |
| 16 | + }, |
| 17 | + }, |
| 18 | + }, |
| 19 | + webpackFinal: async (config) => { |
| 20 | + config.module.rules = config.module.rules.flatMap((rule) => (rule.loader?.includes('swc-loader') ? [ |
| 21 | + rule, |
| 22 | + { |
| 23 | + // In addition to the swc-loader rule from storybook, add a rule which allows transforming ts and tsx files (i.e. to transform node_modules/visyn_core) |
| 24 | + ...rule, |
| 25 | + test: /\.(ts|tsx)$/, |
| 26 | + exclude: [], |
| 27 | + }, |
| 28 | + ] : [rule])); |
| 29 | + |
| 30 | + config.resolve.alias = { |
| 31 | + ...(config.resolve.alias || {}), |
| 32 | + // I have no clue why this is required, but if this is missing we get a "Can't resolve '../../assets/icons/datavisyn_logo.svg' in '.../src/scss'"" |
| 33 | + '../../assets': path.resolve(dirname, '../src/assets'), |
| 34 | + // Add visyn_pro/dist as alias, as we have scss/code imports like visyn_pro/dist/assets/... |
| 35 | + [`${name}/dist`]: path.resolve(dirname, '../src'), |
| 36 | + [`${name}/src`]: path.resolve(dirname, '../src'), |
| 37 | + [name]: path.resolve(dirname, '../src'), |
| 38 | + }; |
| 39 | + return config; |
| 40 | + }, |
| 41 | + docs: { |
| 42 | + autodocs: true, |
| 43 | + }, |
| 44 | +}); |
0 commit comments