IgnorePlugin

此插件会阻止为匹配正则表达式的 importrequire 调用生成模块。

new rspack.IgnorePlugin(options);

选项

  • 类型
| {
    /** A RegExp to test the resource against. */
    resourceRegExp: RegExp;
    /** A RegExp to test the context (directory) against. */
    contextRegExp?: RegExp;
  }
| {
    /** A Filter function that receives `resource` and `context` as arguments, must return boolean. */
    checkResource: (resource: string, context: string) => boolean;
  }
  • 默认值: undefined

示例

使用以下配置时

rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
  plugins: [
    new rspack.IgnorePlugin({
      resourceRegExp: /^\.\/locale$/,
      contextRegExp: /moment$/,
    });
  ],
};

这意味着任何以 'moment' 结尾的目录中的任何匹配 './locale' 的 require 语句都将被忽略。

本页内容