strothj / react-docgen-typescript-loader

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

How to filter props with a regex? #31

Open InamTaj opened 5 years ago

InamTaj commented 5 years ago

I have performed a pretty standard integration of react-docgen-typescript-loader but it shows me all of the inherited props of the function as well. I was able to filter almost half of the props with specifying skipPropsWithoutDoc option in the webpack loader config. Now I'm still being shown the aria-* props which I need to skip. I tried placing regex in the skipPropsWithName option but to no avail.

Take a look: image

As for the filtering function, I have no idea how to specify both of my requirements (filter by regex and filter undocumented props) in the filtering function. Any ideas?

Tech Stack:

Thanks in advance for your help & time!

OzairP commented 5 years ago

Try this

module.exports = (baseConfig, env, config) => {
    // TypeScript support
    config.module.rules.push({
        test: /\.(ts|tsx)$/,
        include: path.resolve(__dirname, '../src'),
        use: [
            {
                loader: require.resolve('ts-loader'),
                options: {
                    transpileOnly: true,
                },
            },
            {
                loader: require.resolve('react-docgen-typescript-loader'),
                options: {
                    propFilter: props => props.parent && props.parent.fileName.startsWith('ui/src'),
                },
            },
        ],
    })
    config.resolve.extensions.push('.ts', '.tsx')

    return config
}

For me, props.parent basename was ui/src but it might be different for you, console.log to find out.