main.js 1.8 KB

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