PageSourceSearch

https://rspack.rs/static/js/async/route-0a41b4f644f4.3f38e73713.js

js rspack.rs collected 2026-10-02 02:41:05 UTC 29,518 bytes, 1 lines download raw bytes

1"use strict";(self.rspackChunkrspack_website=self.rspackChunkrspack_website||[]).push([["7l"],{dB(e,s,r){r.r(s);var n=r("i"),i=r("fj");function o(e){let s={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.h1,{id:"ignoreplugin",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#ignoreplugin",children:"#"}),"IgnorePlugin"]}),"\n",(0,n.jsxs)(s.p,{children:["此插件将会忽略指定的导入文件,让这些 ",(0,n.jsx)(s.code,{children:"import"})," 或 ",(0,n.jsx)(s.code,{children:"require"})," 包含的文件不被打包。"]}),"\n",(0,n.jsxs)(s.h2,{id:"工作原理",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#工作原理",children:"#"}),"工作原理"]}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 会在解析前检查每一处模块引用。对于直接的 ",(0,n.jsx)(s.code,{children:"import"})," 或 ",(0,n.jsx)(s.code,{children:"require"}),",参与匹配的是尚未解析的模块标识符;对于 ",(0,n.jsx)(s.code,{children:"require('./locale/' + name)"})," 等动态模块查找,参与匹配的是从表达式中提取的上下文路径。当配置的正则表达式匹配该值,或过滤函数返回 ",(0,n.jsx)(s.code,{children:"true"})," 时,Rspack 会忽略该模块引用,不再生成对应模块。其他模块引用仍会正常解析并打包。"]}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"IgnorePlugin"})," 不会将被忽略的模块替换为空模块。Rspack 会跳过对该模块的解析,也不会生成对应模块。如果构建产物执行到匹配的 ",(0,n.jsx)(s.code,{children:"import"})," 或 ",(0,n.jsx)(s.code,{children:"require"})," 所生成的代码,这段代码会在运行时抛出一个 ",(0,n.jsx)(s.code,{children:"code"})," 为 ",(0,n.jsx)(s.code,{children:"MODULE_NOT_FOUND"})," 的错误。使用插件前,应确保相关代码不会在目标环境中执行,或引用方代码已经处理了模块不存在的情况。"]}),"\n",(0,n.jsxs)(s.p,{children:["使用 ",(0,n.jsx)(s.a,{href:"#resourceregexp",children:(0,n.jsx)(s.code,{children:"resourceRegExp"})})," 或 ",(0,n.jsx)(s.a,{href:"#checkresource",children:(0,n.jsx)(s.code,{children:"checkResource"})})," 选择要忽略的模块引用。若要根据引用方模块所在的目录限定正则表达式的匹配范围,请将 ",(0,n.jsx)(s.a,{href:"#contextregexp",children:(0,n.jsx)(s.code,{children:"contextRegExp"})})," 与 ",(0,n.jsx)(s.a,{href:"#resourceregexp",children:(0,n.jsx)(s.code,{children:"resourceRegExp"})})," 组合使用。"]}),"\n",(0,n.jsxs)(s.h2,{id:"常见使用场景",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#常见使用场景",children:"#"}),"常见使用场景"]}),"\n",(0,n.jsxs)(s.p,{children:["只有在省略被引用模块不会影响正常运行时,才应使用 ",(0,n.jsx)(s.code,{children:"IgnorePlugin"}),"。常见场景包括:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsx)(s.li,{children:"排除第三方库动态查找、但当前应用并不需要的一组资源,例如未使用的 Moment.js 语言包。"}),"\n",(0,n.jsx)(s.li,{children:"排除可选模块或仅在特定运行环境中使用的模块,前提是相关代码路径不会执行,或引用方代码已经处理模块不存在的情况。"}),"\n",(0,n.jsx)(s.li,{children:"将忽略规则限定在特定包或目录,使其他位置使用相同模块标识符时仍可正常解析。"}),"\n"]}),"\n",(0,n.jsxs)(s.h2,{id:"示例",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#示例",children:"#"}),"示例"]}),"\n",(0,n.jsxs)(s.h3,{id:"忽略指定导入",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#忽略指定导入",children:"#"}),"忽略指定导入"]}),"\n",(0,n.jsxs)(s.p,{children:["以下配置会忽略所有在解析前模块标识符恰好为 ",(0,n.jsx)(s.code,{children:"./optional-feature"})," 的模块引用,不限制引用方模块所在的目录:"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"rspack.config.mjs",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" { rspack } "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" '@rspack/core'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,n.jsx)(s.span,{className:"line"}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  entry"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './src/index.js'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  plugins"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"    new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" rspack"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".IgnorePlugin"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"({"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"      resourceRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\\.\\/optional-feature"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"    })"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  ]"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,n.jsx)(s.p,{children:"例如,入口文件中包含一个与规则匹配的静态导入:"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"src/index.js",lang:"js",children:(0,n.jsx)(s.code,{children:(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './optional-feature'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})})})}),"\n",(0,n.jsxs)(s.p,{children:["由于省略了 ",(0,n.jsx)(s.code,{children:"contextRegExp"}),",这条规则会对所有目录中的模块引用生效,其他模块标识符仍会正常解析。"]}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 不会为 ",(0,n.jsx)(s.code,{children:"./optional-feature"})," 生成模块,也不会将它替换为空模块。生成的 JavaScript 不会保留原始的 ",(0,n.jsx)(s.code,{children:"import"})," 语法,而是在对应位置生成一个缺失模块表达式。入口执行到该表达式时,会抛出一个 ",(0,n.jsx)(s.code,{children:"code"})," 为 ",(0,n.jsx)(s.code,{children:"MODULE_NOT_FOUND"})," 的错误:"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"dist/main.js(简化)",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Object"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  ("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:" __rspack_missing_module"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"}
1,children:"() {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"    const"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" error"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:" new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:" Error"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\"Cannot find module './optional-feature'\""}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:");"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"    error"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:".code "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'MODULE_NOT_FOUND'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"    throw"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" error;"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  })()"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,n.jsx)(s.p,{children:"此示例特意展示执行被忽略的静态导入时产生的运行时错误。"}),"\n",(0,n.jsxs)(s.h3,{id:"忽略-momentjs-语言包",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#忽略-momentjs-语言包",children:"#"}),"忽略 Moment.js 语言包"]}),"\n",(0,n.jsxs)(s.p,{children:["Moment.js 通过 ",(0,n.jsx)(s.code,{children:"require('./locale/' + name)"})," 动态加载语言包。Rspack 会从该表达式中提取 ",(0,n.jsx)(s.code,{children:"./locale"})," 作为上下文路径。若只想在引用方模块位于路径以 ",(0,n.jsx)(s.code,{children:"moment"})," 结尾的目录时忽略这项动态查找,需要同时配置 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 和 ",(0,n.jsx)(s.code,{children:"contextRegExp"}),":"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" rspack"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".IgnorePlugin"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"({"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  resourceRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\\.\\/locale"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  contextRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /moment"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})}),"\n",(0,n.jsx)(s.p,{children:"入口文件可以正常导入 Moment.js:"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"src/index.js",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" moment "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'moment'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,n.jsx)(s.span,{className:"line"}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"console"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".log"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"moment"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"}
1,children:"()"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".format"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"());"})]})]})})}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 会使用提取出的上下文路径 ",(0,n.jsx)(s.code,{children:"./locale"})," 匹配 ",(0,n.jsx)(s.code,{children:"resourceRegExp"}),",而不是使用解析后的路径 ",(0,n.jsx)(s.code,{children:"moment/locale"}),"。两个正则表达式均匹配,因此构建产物会保留 Moment.js 本身,但不会包含 ",(0,n.jsx)(s.code,{children:"moment/locale"})," 中的模块:"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"dist/main.js(简化)",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// 构建产物中包含 Moment.js 核心代ç 
1ã€‚"})}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// 构建产物中不包含 moment/locale/*.js 模块。"})})]})})}),"\n",(0,n.jsxs)(s.h2,{id:"选项",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#选项",children:"#"}),"选项"]}),"\n",(0,n.jsxs)(s.h3,{id:"resourceregexp",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#resourceregexp",children:"#"}),"resourceRegExp"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"类型:"})," ",(0,n.jsx)(s.code,{children:"RegExp"})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"默认值:"})," ",(0,n.jsx)(s.code,{children:"undefined"})]}),"\n"]}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 会在解析前使用 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 进行匹配。对于直接模块引用,参与匹配的是尚未解析的模块标识符;对于动态模块查找,参与匹配的是从表达式中提取的上下文路径。例如,",(0,n.jsx)(s.code,{children:"import './optional-feature'"})," 会以 ",(0,n.jsx)(s.code,{children:"./optional-feature"})," 参与匹配,而 ",(0,n.jsx)(s.code,{children:"require('./locale/' + name)"})," 会以 ",(0,n.jsx)(s.code,{children:"./locale"})," 参与匹配,两者都不会使用解析后的绝对路径。"]}),"\n",(0,n.jsxs)(s.p,{children:["正则表达式匹配且未配置 ",(0,n.jsx)(s.code,{children:"contextRegExp"})," 时,Rspack 不会生成被引用的模块,也不限制引用方模块所在的目录。配置 ",(0,n.jsx)(s.code,{children:"contextRegExp"})," 后,两个正则表达式必须同时匹配。如果省略 ",(0,n.jsx)(s.code,{children:"resourceRegExp"}),",则必须提供 ",(0,n.jsx)(s.code,{children:"checkResource"}),";按照公开选项类型,两者不能同时省略。"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" rspack"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".IgnorePlugin"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"({"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  resourceRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\\.\\/optional-feature"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})}),"\n",(0,n.jsxs)(s.h3,{id:"contextregexp",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#contextregexp",children:"#"}),"contextRegExp"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"类型:"})," ",(0,n.jsx)(s.code,{children:"RegExp"})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:"默认值:"})," ",(0,n.jsx)(s.code,{children:"undefined"})]}),"\n"]}),"\n",(0,n.jsxs)(s.p,{children:["用于匹配引用方模块所在的目录(",(0,n.jsx)(s.code,{children:"context"}),"),该值通常是绝对路径。Rspack 仅在 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 匹配后才检查此正则表达式,两个正则表达式同时匹配时才会停止生成对应模块。"]}),"\n",(0,n.jsxs)(s.p,{children:["省略此选项时,",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 的匹配结果不受引用方模块所在目录的限制。",(0,n.jsx)(s.code,{children:"contextRegExp"})," 不能脱离 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 单独生效;使用函数形式时,应在 ",(0,n.jsx)(s.code,{children:"checkResource"})," 中检查 ",(0,n.jsx)(s.code,{children:"context"})," 参数。"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" rspack"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".IgnorePlugin"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"({"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  resourceRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"^"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\\.\\/optional-feature"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  contextRegExp"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /[/\\\\]legacy"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})}),"\n",(0,n.jsxs)(s.h3,{id:"checkresource",children:[(0,n.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#checkresource",children:"#"}),"checkResource"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"类型:"})}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,n.jsx)(s.code,{children:(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(resource"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" context"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" boolean;"})]})})})}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.strong,{children:"默认值:"})," ",(0,n.jsx)(s.code,{children:"undefined"})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 会在解析每一处模块引用前调用此函数。",(0,n.jsx)(s.code,{children:"resource"})," 与 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 的匹配值相同:对于直接模块引用,它是尚未解析的模块标识符;对于动态模块查找,它是提取出的上下文路径。",(0,n.jsx)(s.code,{children:"context"})," 是引用方模块所在的目录。返回 ",(0,n.jsx)(s.code,{children:"true"})," 时停止解析且不生成对应模块;返回 ",(0,n.jsx)(s.code,{children:"false"})," 时继续处理。"]}
1),"\n",(0,n.jsxs)(s.p,{children:["这是 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 和 ",(0,n.jsx)(s.code,{children:"contextRegExp"})," 的函数形式替代方案。如果省略此选项,则必须提供 ",(0,n.jsx)(s.code,{children:"resourceRegExp"}),"。需要按目录限制函数的匹配范围时,请在函数内部检查 ",(0,n.jsx)(s.code,{children:"context"}),"。"]}),"\n",(0,n.jsxs)(s.p,{children:["Rspack 会先执行 ",(0,n.jsx)(s.code,{children:"checkResource"}),",再检查正则表达式选项。如果同时提供两种形式,返回 ",(0,n.jsx)(s.code,{children:"true"})," 的结果优先,会立即停止解析且不生成对应模块;返回 ",(0,n.jsx)(s.code,{children:"false"})," 后,Rspack 会继续检查 ",(0,n.jsx)(s.code,{children:"resourceRegExp"})," 和 ",(0,n.jsx)(s.code,{children:"contextRegExp"}),"。只有两种形式都未忽略该模块引用时,Rspack 才会继续执行常规解析。"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,n.jsxs)(s.code,{children:[(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"new"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" rspack"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".IgnorePlugin"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"({"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"  checkResource"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(resource"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" context) {"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"    return"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" resource "}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"==="}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './optional-feature'"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:" &&"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /[/\\\\]legacy"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".test"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(context);"})]}),"\n",(0,n.jsxs)(s.span,{className:"line",children:[(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"  }"}),(0,n.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(s.span,{className:"line",children:(0,n.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})})]})}function l(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(o,{...e})}):o(e)}l.__RSPRESS_PAGE_META={},l.__RSPRESS_PAGE_META["zh%2Fplugins%2Fignore-plugin.mdx"]={toc:[{id:"工作原理",text:"工作原理",depth:2},{id:"常见使用场景",text:"常见使用场景",depth:2},{id:"示例",text:"示例",depth:2},{id:"忽略指定导入",text:"忽略指定导入",depth:3},{id:"忽略-momentjs-语言包",text:"忽略 Moment.js 语言包",depth:3},{id:"选项",text:"选项",depth:2},{id:"resourceregexp",text:"resourceRegExp",depth:3},{id:"contextregexp",text:"contextRegExp",depth:3},{id:"checkresource",text:"checkResource",depth:3}],title:"IgnorePlugin",headingTitle:"IgnorePlugin",frontmatter:{description:"忽略指定的导入,使对应模块不进入构建产物。"}},r.d(s,{default:()=>l})}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.