function findWebpackPlugin(config, test) {
    /** @type {(plugin: any) => boolean} */
    const checkPlugin =
        typeof test === 'string'
            ? plugin => plugin.constructor.name === test
            : test instanceof RegExp
            ? plugin => test.test(plugin.constructor.name)
            : test;

    for (const plugin of config.plugins || []) {
        if (checkPlugin(plugin)) {
            return plugin;
        }
    }
}
Check that a matching webpack rule can be found

@param {import("webpack").Configuration} config
@param {string|RegExp|((plugin: any) => boolean)} test
@returns {NonNullable<import('webpack').Configuration['plugins']>[0] | undefined}