Browse Source

Fix Storybook not supporting TypeScript declare class fields

Thibaud Colas 2 years ago
parent
commit
0246d3a6f4
1 changed files with 12 additions and 0 deletions
  1. 12 0
      client/storybook/main.js

+ 12 - 0
client/storybook/main.js

@@ -14,6 +14,18 @@ module.exports = {
   core: {
     builder: 'webpack5',
   },
+  // Redefine Babel config to allow TypeScript class fields `declare`.
+  // See https://github.com/storybookjs/storybook/issues/12479.
+  // The resulting configuration is closer to Wagtail’s Webpack + TypeScript setup,
+  // preventing other potential issues with JS transpilation differences.
+  babel: async (options) => ({
+    ...options,
+    plugins: [],
+    presets: [
+      ['@babel/preset-typescript', { allowDeclareFields: true }],
+      ['@babel/preset-react', { runtime: 'automatic' }],
+    ],
+  }),
   webpackFinal: (config) => {
     /* eslint-disable no-param-reassign */