strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Performance issue with Storybook 5, babel-loader and TypeScript #49

Open 1-Felix opened 5 years ago

1-Felix commented 5 years ago

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

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

swyxio commented 5 years ago

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?

gilbarbara commented 4 years ago

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

  {
    name: '@storybook/preset-typescript',
    options: {
      tsLoaderOptions: {
        transpileOnly: true,
      },
    },
  }
dgreene1 commented 4 years ago

@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.