plugins_ignore.js

// @ts-check

/**
 * @file src/plugins/ignore.js
 * @copyright @spmhome @_2025
 * @author Scott Meesseman @spmeesseman
 *//** */

const WpwPlugin = require("./base");


/**
 * @augments WpwPlugin
 */
class WpwIgnorePlugin extends WpwPlugin
{
    /**
     * @param {WpwPluginOptions} options Plugin options to be applied
     */
    constructor(options)
    {
        super(options);
        this.buildOptions = /** @type {WpwBuildOptionsExportConfig<"ignore">} */(this.buildOptions);
    }

    /**
     * @override
     * @param {WpwBuild} build
     */
	static create = WpwIgnorePlugin.wrap.bind(this);

    /**
     * @override
     * @param {WebpackCompiler} _compiler
     */
    onApply(_compiler)
    {
    }

	/**
	 * @override
     * @param {WebpackCompiler} compiler
     * @param {boolean} [applyFirst]
	 * @returns {WebpackPluginInstance | undefined}
	 */
	getVendorPlugin = (compiler, applyFirst) =>
    {
        if (!applyFirst)
        {
            /** @type {WebpackIgnorePlugin | undefined} */
            let plugin;
            if (this.buildOptions.momentLocales) //  && build.mode === "production")
            {
                const { IgnorePlugin } = this.build.wp || compiler.webpack;
                plugin = new IgnorePlugin(
                {
                    resourceRegExp: /^\.[\\/]locale$/,
                    contextRegExp: /moment$/
                });
            }
            return plugin;
        }
    };
}


module.exports = WpwIgnorePlugin.create;