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 語句都會被忽略。

本頁內容