strothj / react-docgen-typescript-loader

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

Usage of PropFilter with webpack plugin #27

Open Mskalba opened 5 years ago

Mskalba commented 5 years ago

Hi I have react-docgen-typescript-webpack-plugin used in storybook webpack configuration.

const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin');

defaultConfig.plugins.push(new TSDocgenPlugin());

How should I pass options with propFilter to that plugin so it can actually filter them?

i also tried something like:

loaders: [
      {
        loader: require.resolve('awesome-typescript-loader')
      },
      {
        loader: require.resolve('react-docgen-typescript-loader'),
        options: {
          propFilter: (prop) => prop.name === 'variant'

        }
      },
    ]

The propFilter is called then, but the props are not filtered.

strothj commented 5 years ago

Hello,

I left an example explanation here: https://github.com/strothj/react-docgen-typescript-loader/pull/21

loaders: [ should be use: [ due to that use being deprecated. It's aliased per the explanation here: https://webpack.js.org/configuration/module/#rule-loaders so I don't think that would affect it.

It looks like it should work but please double check against the linked pull request there. I'm not too familiar with that feature to be honest.

You'll want to use 'react-docgen-typescript-loader. react-docgen-typescript-webpack-plugin is an older implementation.

nmackey commented 5 years ago

So I'm seeing this same problem and it seems to be related to using other loaders with react-docgen-typescript-loader. I currently use ts-loader with thread-loader & cache-loader. With this setup the propFilter function doesn't seem to work. If I remove thread-loader & cache-loader the propFilter works fine. skipPropsWithoutDoc: true seems to work either way. I haven't tried using awesome-typescript-loader with this plugin yet but I'm guessing it could be the same issue as I know it can use caching as well. @strothj if you have any ideas on how to get propFilter working with the use of thread-loader & cache-loader let me know as they greatly increase compilation time.