react-docgen-typescript-loader icon indicating copy to clipboard operation
react-docgen-typescript-loader copied to clipboard

Performance issue with Storybook 5, babel-loader and TypeScript

Open 1-Felix opened this issue 5 years ago • 3 comments

Hey, I'm currently running into performance issues when I try to display a props table in storybook 5.

Current Behavior

Starting Storybook takes currently around 180 seconds for 35 components. By simply leaving out react-docgen-typescript-loader, build time goes down to 40 seconds.

slow fast

Context

The project is build using react and typescript. But instead of the awesome-typecript-loader (like suggested in the storybook-docs) I'm using the babel-loader.

I'm using react-docgen-typescript-loader in order to display the props in the newly released docs-addon from storybook.

My custom webpack.config.js looks like this:

const path = require('path')

module.exports = ({ config, mode, defaultConfig }) => {
  config.module.rules.push(
    {
      test: /\.(ts|tsx)$/,
      exclude: path.resolve(__dirname, '../node_modules/'),
      use: [
        {
          loader: 'babel-loader',
        },
        {
           // commenting this out, improves performance significantly 
           loader: 'react-docgen-typescript-loader',
        },
      ],
    },
    {
      test: /\.stories\.(ts|tsx)$/,
      exclude: path.resolve(__dirname, '../node_modules/'),
      use: [
        {
          // needed for storysource-addon
          loader: require.resolve('@storybook/addon-storysource/loader'),
          options: { parser: 'typescript' },
        },
        {
          // needed for docs addon
          loader: '@storybook/source-loader',
          options: { injectParameters: true },
        },
      ],
    },
  )
  config.resolve.extensions.push('.ts', '.tsx')
  return config
}

What I tried

The listed attempts didn't improve build time or made it worse.

Specs

  • Operating System: Windows 10
  • Framework: React 16.8, Create-react-app 3.0.1
  • Typescript 3.5.1
  • Storybook 5.2.0-alpha.35

If you need any additional information, please let me know.

1-Felix avatar Jul 08 '19 06:07 1-Felix

a repro would be nice. can you take the exact same storybook setup and webpack config and put in in a small repo with just 1 component?

swyxio avatar Jul 08 '19 15:07 swyxio

Adding transpileOnly: true to @storybook/preset-typescript options helped a lot.

  {
    name: '@storybook/preset-typescript',
    options: {
      tsLoaderOptions: {
        transpileOnly: true,
      },
    },
  }

gilbarbara avatar Nov 21 '19 11:11 gilbarbara

@felixkeller98 I'd be interested to see the final config that you settled on. Can you share yours?

From what I've seen, TypeScript and the Docs addon are not yet quite plug-in-play.

dgreene1 avatar Apr 14 '20 16:04 dgreene1