main.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. module.exports = {
  2. stories: [
  3. '../../client/**/*.stories.mdx',
  4. '../../client/**/*.stories.@(js|tsx)',
  5. '../../wagtail/**/*.stories.*',
  6. ],
  7. addons: ['@storybook/addon-docs', '@storybook/addon-controls'],
  8. framework: {
  9. name: '@storybook/react-webpack5',
  10. options: {},
  11. },
  12. // Redefine Babel config to allow TypeScript class fields `declare`.
  13. // See https://github.com/storybookjs/storybook/issues/12479.
  14. // The resulting configuration is closer to Wagtail’s Webpack + TypeScript setup,
  15. // preventing other potential issues with JS transpilation differences.
  16. babel: async (options) => ({
  17. ...options,
  18. plugins: [],
  19. presets: [
  20. ['@babel/preset-typescript', { allowDeclareFields: true }],
  21. ['@babel/preset-react', { runtime: 'automatic' }],
  22. ],
  23. }),
  24. webpackFinal: (config) => {
  25. /* eslint-disable no-param-reassign */
  26. const rules = [
  27. {
  28. test: /\.(scss|css)$/,
  29. use: [
  30. 'style-loader',
  31. {
  32. loader: 'css-loader',
  33. options: {
  34. url: false,
  35. },
  36. },
  37. {
  38. loader: 'postcss-loader',
  39. options: {
  40. postcssOptions: {
  41. plugins: ['tailwindcss', 'autoprefixer', 'cssnano'],
  42. },
  43. },
  44. },
  45. 'sass-loader',
  46. ],
  47. },
  48. {
  49. test: /\.(md|html)$/,
  50. type: 'asset/source',
  51. },
  52. ];
  53. config.module.rules = config.module.rules.concat(rules);
  54. // Allow using path magic variables to reduce boilerplate in stories.
  55. config.node = {
  56. __filename: true,
  57. __dirname: true,
  58. };
  59. return config;
  60. },
  61. docs: {
  62. autodocs: true,
  63. },
  64. };