function findWebpackLoader(config, loader, forRule = undefined) {
    /** @type {(loader: string) => boolean} */
    const checkLoader =
        typeof loader === 'string'
            ? str => new RegExp(`[/\\\\]${loader}[/\\\\]`).test(str)
            : loader instanceof RegExp
            ? str => loader.test(str)
            : loader;

    for (const rule of getRules(
        config,
        rule => forRule === undefined || rule === forRule
    )) {
        for (const found of getLoaders(rule)) {
            if (checkLoader(found.loader)) {
                return found;
            }
        }
    }
}
Check that a matching rule with the given loader can be found

@param {import("webpack").Configuration} config
@param {string|RegExp|((loader: string) => boolean)} loader
@param {import('webpack').RuleSetRule|undefined} [forRule]