main.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const path = require("path");
  2. module.exports = {
  3. stories: ["../src/**/*.stories.tsx"],
  4. addons: [
  5. "@storybook/addon-links",
  6. "@storybook/addon-essentials",
  7. "@storybook/addon-a11y",
  8. "@storybook/addon-storysource",
  9. "storybook-addon-rtl"
  10. ],
  11. framework: {
  12. name: '@storybook/nextjs',
  13. options: {},
  14. },
  15. staticDirs: ['./../public'],
  16. typescript: {
  17. check: false,
  18. checkOptions: {},
  19. // ideally we use `react-docgen-typescript`. But there's still some issue, related to webpack 5.
  20. // so we use `react-docgen` for now
  21. reactDocgen: "react-docgen",
  22. // reactDocgenTypescriptOptions: {
  23. // shouldExtractLiteralValuesFromEnum: true,
  24. // propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
  25. // },
  26. },
  27. webpackFinal: async (config) => {
  28. // Add support for absolute paths
  29. config.resolve.modules = [
  30. ...(config.resolve.modules || []),
  31. path.resolve("./"),
  32. ];
  33. // @/ root alias doesn't work in storybook, so we have to write the aliases manually
  34. const otherAliases = ["components", "utils", "redux", "hooks", "contexts"];
  35. // Add support for module aliases (same aliases in tsconfig.json)
  36. config.resolve.alias = {
  37. ...(config.resolve.alias || {}),
  38. "@/icons": path.resolve(__dirname, "../public/icons"),
  39. "@/public": path.resolve(__dirname, "../public"),
  40. "@/dls": path.resolve(__dirname, "../src/components/dls"),
  41. "@/api": path.resolve(__dirname, "../src/api"),
  42. "@/data": path.resolve(__dirname, "../data"),
  43. "@/types": path.resolve(__dirname, "../types"),
  44. ...otherAliases.reduce(
  45. (acc, folder) => ({
  46. ...acc,
  47. [`@/${folder}`]: path.resolve(__dirname, "../src", folder),
  48. }),
  49. {}
  50. ),
  51. };
  52. const fileLoaderRule = config.module.rules.find((rule) =>
  53. Array.isArray(rule.test)
  54. ? rule.test[0]?.test(".svg")
  55. : rule.test?.test(".svg")
  56. );
  57. fileLoaderRule.exclude = /\.svg$/;
  58. // This is needed for inline svg imports
  59. config.module.rules.push({
  60. test: /\.svg$/,
  61. exclude: /node_modules/,
  62. use: [
  63. {
  64. loader: "@svgr/webpack",
  65. options: {
  66. prettier: false,
  67. svgo: true,
  68. svgoConfig: {
  69. plugins: [
  70. {
  71. name: "preset-default",
  72. params: {
  73. overrides: {
  74. removeViewBox: false,
  75. },
  76. },
  77. },
  78. ],
  79. },
  80. },
  81. },
  82. ],
  83. });
  84. return config;
  85. },
  86. };