1"use strict";(self.rspackChunkrspack_website=self.rspackChunkrspack_website||[]).push([["d0"],{uL(s,e,n){n.r(e);var r=n("i"),i=n("fj"),l=n("V"),o=n("sX"),c=n("yW");function a(s){let e={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,i.R)(),...s.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.h1,{id:"æ¨¡åæ¹æ³",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#æ¨¡åæ¹æ³",children:"#"}),"æ¨¡åæ¹æ³"]}),"\n",(0,r.jsxs)(e.p,{children:["å½ä½¿ç¨ Rspack æå
åºç¨ç¨åºæ¶ï¼ä½ å¯ä»¥éæ©å¤ç§æ¨¡åè¯æ³é£æ ¼ï¼å
æ¬ ",(0,r.jsx)(e.a,{href:"https://nodejs.org/api/esm.html#modules-ecmascript-modules",rel:"noopener noreferrer",target:"_blank",children:"ES modules"})," å ",(0,r.jsx)(e.a,{href:"https://nodejs.org/api/modules.html",rel:"noopener noreferrer",target:"_blank",children:"CommonJS"}),"ã"]}),"\n",(0,r.jsx)(e.p,{children:"尽管 Rspack æ¯æå¤ç§æ¨¡åè¯æ³ï¼ä½æä»¬è¿æ¯å»ºè®®å°½é使ç¨ä¸è´çè¯æ³ï¼ä»¥æ¤é¿å
ä¸äºå¥æªçè¡ä¸ºå bugã"}),"\n",(0,r.jsxs)(e.p,{children:["äºå®ä¸ï¼å½è·ç¦»æè¿ç ",(0,r.jsx)(e.code,{children:"package.json"})," æä»¶ä¸ ",(0,r.jsx)(e.a,{href:"https://nodejs.org/api/packages.html#type",rel:"noopener noreferrer",target:"_blank",children:'"type"'})," åæ®µå¼ä¸º ",(0,r.jsx)(e.code,{children:'"module"'})," æ ",(0,r.jsx)(e.code,{children:'"commonjs"'})," æ¶ï¼Rspack ä¼å¯¹ ",(0,r.jsx)(e.code,{children:".mjs"})," æä»¶ã",(0,r.jsx)(e.code,{children:".cjs"})," æä»¶æ",(0,r.jsx)(e.code,{children:".js"})," æä»¶è¿è¡å¯¹åºçå¤çï¼"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["æä»¶åç¼ä¸º ",(0,r.jsx)(e.code,{children:".mjs"}),"ï¼æè
",(0,r.jsx)(e.code,{children:"package.json"})," ä¸ ",(0,r.jsx)(e.code,{children:'"type": "module"'})," ä¸åç¼ä¸º ",(0,r.jsx)(e.code,{children:".js"})," æ¶ï¼","\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["ä¸å
è®¸ä½¿ç¨ CommonJSï¼å¦ ",(0,r.jsx)(e.code,{children:"require"}),"ï¼",(0,r.jsx)(e.code,{children:"module.exports"})," æ ",(0,r.jsx)(e.code,{children:"exports"})]}),"\n",(0,r.jsxs)(e.li,{children:["å¼å
¥æä»¶æ¶éæå®æ©å±åï¼ä¾å¦ï¼åºä½¿ç¨ ",(0,r.jsx)(e.code,{children:"import './src/App.mjs'"}),"ï¼èé ",(0,r.jsx)(e.code,{children:"import './src/App'"})]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:["æä»¶åç¼ä¸º ",(0,r.jsx)(e.code,{children:".cjs"}),"ï¼æè
",(0,r.jsx)(e.code,{children:"package.json"})," ä¸ ",(0,r.jsx)(e.code,{children:'"type": "commonjs"'})," ä¸åç¼ä¸º ",(0,r.jsx)(e.code,{children:".js"})," æ¶ï¼","\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["ä¸å
è®¸ä½¿ç¨ ESMï¼å¦ ",(0,r.jsx)(e.code,{children:"import"})," å ",(0,r.jsx)(e.code,{children:"export"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.h2,{id:"es-modules-æ¨è",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#es-modules-æ¨è",children:"#"}),"ES modules (æ¨è)"]}),"\n",(0,r.jsxs)(e.p,{children:["Rspack åçæ¯æ ES modules è¯æ³ï¼å¯ä»¥ä½¿ç¨éæç ",(0,r.jsx)(e.code,{children:"import"}),"ã",(0,r.jsx)(e.code,{children:"export"})," å ",(0,r.jsx)(e.code,{children:"import()"})," è¯æ³ã"]}),"\n",(0,r.jsx)(l.Pq,{type:"warning",title:"Warning",children:(0,r.jsx)(e.p,{children:"\nå¦æä½¿ç¨å
¶ä»ç ES6+ ç¹æ§ï¼ä½ ä»ç¶éè¦å¼å
¥ SWC æ Babel è¿è¡è½¬æ¢ã"})}),"\n",(0,r.jsxs)(e.h3,{id:"import",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#import",children:"#"}),"import"]}),"\n",(0,r.jsxs)(e.p,{children:["éæ ",(0,r.jsx)(e.code,{children:"import"})," å¦ä¸ä¸ªæ¨¡åç ",(0,r.jsx)(e.code,{children:"export"}),"ã"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" MyModule "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './my-module.js'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" { NamedExport } "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './other-module.js'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})]})})}),"\n",(0,r.jsxs)(e.p,{children:["ä½ è¿å¯ä»¥ ",(0,r.jsx)(e.code,{children:"import"})," Data URIï¼è¿å
è®¸ä½ ç´æ¥å¨å¯¼å
¥è¯å¥ä¸åµå
¥ Base64 ç¼ç ç JavaScript 代ç ï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// çåäº import ä¸ä¸ªå
å« `console.log('hello')` çæ¨¡å"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'data:text/javascript;charset=utf-8;base64,Y29uc29sZS5sb2coJ2hlbGxvJyk='"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// çåäº import ä¸ä¸ªå
å« `export const number = 42;` çæ¨¡å"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" { number } "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOw=='"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"export",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#export",children:"#"}),"export"]}
1),"\n",(0,r.jsx)(e.p,{children:"å°ä»»ä½å
容ä½ä¸ºé»è®¤å¯¼åºæå
·å导åºã"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å
·å导åº"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" var"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" Count "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" 5"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" Multiply"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(a"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" b) {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" return"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" a "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"*"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" b;"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// é»è®¤å¯¼åº"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // Some data..."})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"dynamic-import",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#dynamic-import",children:"#"}),"Dynamic import()"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(path"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" Promise"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})})})}),"\n",(0,r.jsxs)(e.p,{children:["卿å 载模åï¼åè ",(0,r.jsx)(e.a,{href:"/zh/guide/optimization/code-splitting.html#%E5%8A%A8%E6%80%81%E5%AF%BC%E5%85%A5dynamic-import",children:"Dynamic import"})," äºè§£æ´å¤ã"]}),"\n",(0,r.jsxs)(e.p,{children:["对 ",(0,r.jsx)(e.code,{children:"import()"})," çè°ç¨è¢«è§ä¸ºåå²ç¹ï¼è¿æå³ç请æ±ç模ååå
¶å模å被æåæåç¬ç chunkã"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"module"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".hot) {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'lodash'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".then"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"((_) "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // ä½¿ç¨ lodash åäºäºæ
..."})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" });"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,r.jsx)(l.Pq,{type:"warning",title:"Warning",children:(0,r.jsxs)(e.p,{children:["\næ¤åè½å
é¨ä¾èµäº ",(0,r.jsx)(e.code,{children:"Promise"}),"ãå¦æä½ å¨æ§çæµè§å¨ä¸ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"import()"}),"ï¼è¯·è®°å¾ä½¿ç¨ç±»ä¼¼äº ",(0,r.jsx)(e.a,{href:"https://github.com/zloirock/core-js",rel:"noopener noreferrer",target:"_blank",children:"core-js"}),"ï¼ ",(0,r.jsx)(e.a,{href:"https://github.com/stefanpenner/es6-promise",rel:"noopener noreferrer",target:"_blank",children:"es6-promise"})," æ ",(0,r.jsx)(e.a,{href:"https://github.com/taylorhakes/promise-polyfill",rel:"noopener noreferrer",target:"_blank",children:"promise-polyfill"})," ç polyfill æ¥æ¨¡æ ",(0,r.jsx)(e.code,{children:"Promise"}),"ã"]})}),"\n",(0,r.jsxs)(e.h3,{id:"import-ä¸çå¨æè¡¨è¾¾å¼",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#import-ä¸çå¨æè¡¨è¾¾å¼",children:"#"}),"import() ä¸çå¨æè¡¨è¾¾å¼"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"import()"})," æ æ³ä½¿ç¨å®å
¨å¨æç导å
¥è¯å¥ï¼ä¾å¦ ",(0,r.jsx)(e.code,{children:"import(foo)"}),"ãå 为 ",(0,r.jsx)(e.code,{children:"foo"})," å¯è½æ¯ç³»ç»æé¡¹ç®ä¸ä»»ä½æä»¶çä»»ä½è·¯å¾ã"]}
1),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"import()"})," å¿
é¡»è³å°å
å«ä¸äºå
³äºæ¨¡åæå¨ä½ç½®çä¿¡æ¯ãå¯ä»¥å°æå
éå¶å¨ç¹å®ç®å½æä¸ç»æä»¶ä¸ï¼è¿æ ·å½ä½ 使ç¨å¨æè¡¨è¾¾å¼æ¶ï¼å¨ ",(0,r.jsx)(e.code,{children:"import()"})," è°ç¨ä¸å¯è½è¢«è¯·æ±çæ¯ä¸ªæ¨¡åé½ä¼è¢«å
æ¬è¿æ¥ã"]}),"\n",(0,r.jsxs)(e.p,{children:["ä¾å¦ï¼",(0,r.jsx)(e.code,{children:"import(./locale/${language}.json)"})," ä¼å° ",(0,r.jsx)(e.code,{children:"./locale"})," ç®å½ä¸çæ¯ä¸ª ",(0,r.jsx)(e.code,{children:".json"})," æä»¶é½è¢«æå
è¿æ°ç代ç åãå¨è¿è¡æ¶ï¼ä¸æ¦åé ",(0,r.jsx)(e.code,{children:"language"})," 被计ç®åºæ¥ï¼ä»»ä½å ",(0,r.jsx)(e.code,{children:"english.json"})," æ ",(0,r.jsx)(e.code,{children:"german.json"})," è¿æ ·çæä»¶é½å°å¯ä¾ä½¿ç¨ã"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// æ³è±¡ä¸ä¸ï¼å¦ææä»¬æä¸ç§æ¹æ³å¯ä»¥ä» Cookie æå
¶ä»åå¨ä¸è·åè¯è¨"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" detectVisitorLanguage"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"`./locale/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:".json`"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".then"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"((module) "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // åä¸äºç¿»è¯ç¸å
³çäºæ
"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"magic-comments",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#magic-comments",children:"#"}),"import() ä¸çéæ³æ³¨é"]}),"\n",(0,r.jsx)(c.a,{specific:["Rspack","Webpack"]}),"\n",(0,r.jsx)(e.p,{children:"éè¿å import è¯å¥æ·»å 注éï¼å¯ä»¥æå® chunk åç§°ãå 载模å¼çè¡ä¸ºã"}),"\n",(0,r.jsxs)(l.Pq,{type:"tip",title:"Tip",children:[(0,r.jsxs)(e.p,{children:["\nä» Rspack 2.1.0 å¼å§ï¼æ¨è使ç¨ä¸æ¹ç ",(0,r.jsx)(e.code,{children:"rspack"})," åç¼éæ³æ³¨éã对åºç ",(0,r.jsx)(e.code,{children:"webpack"})," åç¼æ³¨éä»ä¼è¢«å
¼å®¹æ¯æï¼ä¾å¦ ",(0,r.jsx)(e.code,{children:"webpackIgnore"})," çä»·äº ",(0,r.jsx)(e.code,{children:"rspackIgnore"}),"ã"]}),(0,r.jsxs)(e.p,{children:["䏿¹ç¤ºä¾ç»ä¸ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"rspack"})," åç¼ï¼å¦éå
¼å®¹ webpackï¼å¯ä»¥å°å
¶æ¿æ¢ä¸ºå¯¹åºç ",(0,r.jsx)(e.code,{children:"webpack"})," åç¼ã"]})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å个模å"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackChunkName: "my-chunk-name" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackMode: "lazy" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackFetchPriority: "high" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'module'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å¤ä¸ªå¯è½æ¨¡å"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackInclude: /\\.json$/ */"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackExclude: /\\.noimport\\.json$/ */"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackChunkName: "my-chunk-name" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackMode: "lazy" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackPrefetch: true */"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackPreload: true */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" `./locale/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"`"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackignore",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackignore",children:"#"}),"rspackIgnore"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:"boolean"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackIgnore"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["设置为 ",(0,r.jsx)(e.code,{children:"true"})," æ¶ï¼Rspack å°è·³è¿å¯¹è¯¥å¨æå¯¼å
¥çéæåæåæå
å¤çãå
·ä½è¡¨ç°ä¸ºï¼"]}),"\n",(0,r.jsxs)(e.ol,{children:["\n",(0,r.jsx)(e.li,{children:"æå»ºæ¶ä¸ä¼åæè¯¥æ¨¡åçä¾èµå
³ç³»"}),"\n",(0,r.jsx)(e.li,{children:"该模åä¸ä¼è¢«æå
为ç¬ç«ç chunk æä»¶"}),"\n",(0,r.jsxs)(e.li,{children:["导å
¥æä½å°å¨è¿è¡æ¶ç±æµè§å¨åç ",(0,r.jsx)(e.code,{children:"import()"})," æ§è¡"]}),"\n"]}),"\n",(0,r.jsx)(e.p,{children:"è¿å¨éè¦ä»å¤é¨ CDN 卿å è½½ ESM æ ¼å¼çç¬¬ä¸æ¹åºæ¶ç¹å«æç¨ï¼ä¾å¦ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'https://esm.sh/react'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackIgnore: true */"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".then"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"((React) "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" console"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".log"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"React"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".version); "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// 19.0.0"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"});"})})]})})}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"rspackIgnore"})," åæ ·éç¨äº ",(0,r.jsx)(e.code,{children:"new URL()"})," è¯æ³ãé»è®¤æ
åµä¸ï¼Rspack ä¼è§£æ ",(0,r.jsx)(e.code,{children:"new URL()"})," ä¸çæ¨¡åæ è¯ç¬¦ï¼å¹¶å°å
¶å¼ç¨ç模åæå
å°æå»ºäº§ç©ä¸ãå½ä½ éè¦ Rspack è·³è¿æä¸ª ",(0,r.jsx)(e.code,{children:"new URL()"})," çå¤çæ¶ï¼å¯ä»¥æ·»å ",(0,r.jsx)(e.code,{children:"rspackIgnore: true"})," 注éï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"}
1,children:"// Rspack ä¼å¤çè¿ä¸ª URLï¼å° './index.css' æå
å°æå»ºäº§ç©ä¸"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" url1"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" new"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" URL"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'./index.css'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"."}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"meta"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".url);"})]}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// Rspack ä¼å¿½ç¥è¿ä¸ª URLï¼ä¿æåå§çæ¨¡åæ è¯ç¬¦"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" url2"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" new"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" URL"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"/* rspackIgnore: true */"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './index.css'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"."}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"meta"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".url);"})]}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// åæ ·æ¯æ `webpackIgnore`"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" url3"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" new"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" URL"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"/* webpackIgnore: true */"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './index.css'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"."}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"meta"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".url);"})]})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackmode",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackmode",children:"#"}),"rspackMode"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:'"eager" | "lazy" | "weak" | "lazy-once"'})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackMode"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"é»è®¤å¼ï¼"})," ",(0,r.jsx)(e.code,{children:"'lazy'"})]}),"\n"]}),"\n",(0,r.jsx)(e.p,{children:"å¯ä»¥æå®ä»¥ä¸åçæ¨¡å¼è§£æå¨æå¯¼å
¥ãæ¯æä»¥ä¸é项ï¼"}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"'lazy'"}),"ï¼é»è®¤å¼ï¼ï¼ä¸ºæ¯ä¸ªå¯è½å¯¼å
¥ç模åçæä¸ä¸ªå¯å»¶è¿å è½½ç chunkã"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"'lazy-once'"}),"ï¼å°å¨æå¯¼å
¥ä¸ä¸æä¸çææå¯è½æ¨¡åçæå°åä¸ä¸ªå¼æ¥ chunk ä¸ãç¬¬ä¸æ¬¡è°ç¨ ",(0,r.jsx)(e.code,{children:"import()"})," æ¶å 载该 chunkï¼åç»è°ç¨ä¼å¤ç¨å®ãæ¤æ¨¡å¼éç¨äº ",(0,r.jsx)(e.code,{children:"import('./locales/' + language + '.json')"})," è¿ç±»å¯è½å¹é
å¤ä¸ªæ¨¡åçå¨æè¡¨è¾¾å¼ã"]}
1),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"'eager'"}),"ï¼ä¸çæé¢å¤ç chunkï¼èæ¯å°ææå¯è½çæ¨¡åæ¾å
¥å½å chunkï¼å æ¤ä¸ä¼äº§çé¢å¤çç½ç»è¯·æ±ã",(0,r.jsx)(e.code,{children:"import()"})," ä»ç¶è¿å Promiseï¼ä¸æ¨¡åè¦çå°è°ç¨ ",(0,r.jsx)(e.code,{children:"import()"})," æ¶æä¼æ§è¡ã"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"'weak'"}),"ï¼ä»
卿¨¡åå·²éè¿å
¶ä»æ¹å¼å è½½æ¶æè§£ææåï¼ä¾å¦æ¨¡åå·²å
å«å¨å¦ä¸ä¸ªå è½½å®æç chunk ä¸ãæ¤æ¨¡å¼ä¸ä¼åèµ·ç½ç»è¯·æ±ï¼å¦ææ¨¡åä¸å¯ç¨ï¼Promise ä¼è¢«æç»ãå®ä¸»è¦ç¨äºç±æå¡ç«¯ç¡®ä¿æé chunk å·²å
å«å¨åå§ååºä¸ç SSR åºæ¯ã"]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["ä¾å¦ï¼ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"lazy-once"})," å°ææå¯è½çè¯è¨æ¨¡ååå¹¶å°åä¸ä¸ªå¼æ¥ chunk ä¸ï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" detectVisitorLanguage"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" messages"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackMode: "lazy-once" */'})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" `./locales/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:".js`"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackprefetch",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackprefetch",children:"#"}),"rspackPrefetch"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"number"}),"ï¼é¢åä¼å
级"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"boolean"}),"ï¼",(0,r.jsx)(e.code,{children:"false"})," 表示ä¸é¢åï¼",(0,r.jsx)(e.code,{children:"true"})," 表示é¢åä¸ä¼å
级为 ",(0,r.jsx)(e.code,{children:"0"})]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackPrefetch"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["åè¯æµè§å¨å°æ¥å¯è½éè¦è¯¥èµæºæ¥è¿è¡æäºå¯¼èªè·³è½¬ï¼è¯¦æ
请æ¥ç",(0,r.jsx)(e.a,{href:"/zh/guide/optimization/code-splitting.html#prefetchingpreloading-%E6%A8%A1%E5%9D%97",children:"é¢å/é¢è½½æ¨¡å"}),"ã"]}),"\n",(0,r.jsx)(e.p,{children:"ä¾å¦ï¼å½ç¶ chunk å è½½åï¼æµè§å¨ä¼å¨ç©ºé²æ¶é¢åç¼è¾å¨ chunkï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" openEditor"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"}
1,children:"() {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" return"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackPrefetch: true */"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './editor.js'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" );"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,r.jsx)(e.p,{children:"ä¹å¯ä»¥ä½¿ç¨æ°å设置é¢åä¼å
级ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"/* rspackPrefetch: 10 */"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './editor.js'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackpreload",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackpreload",children:"#"}),"rspackPreload"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"number"}),"ï¼é¢è½½ä¼å
级"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"boolean"}),"ï¼",(0,r.jsx)(e.code,{children:"false"})," 表示ä¸é¢è½½ï¼",(0,r.jsx)(e.code,{children:"true"})," 表示é¢è½½ä¸ä¼å
级为 ",(0,r.jsx)(e.code,{children:"0"})]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackPreload"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["åè¯æµè§å¨å¨å½åå¯¼èªæé´å¯è½éè¦è¯¥èµæºï¼è¯¦æ
请æ¥ç",(0,r.jsx)(e.a,{href:"/zh/guide/optimization/code-splitting.html#prefetchingpreloading-%E6%A8%A1%E5%9D%97",children:"é¢å/é¢è½½æ¨¡å"}),"ã"]}),"\n",(0,r.jsx)(e.p,{children:"ä¾å¦ï¼å¨å è½½ç¶ chunk çåæ¶é¢è½½å¾è¡¨åºï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" async"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" renderDashboard"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"() {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" { "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"renderChart"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" } "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackPreload: true */"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './chart.js'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" );"})}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" renderChart"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"}
1,children:"();"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackchunkname",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackchunkname",children:"#"}),"rspackChunkName"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:"string"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackChunkName"})]}),"\n"]}),"\n",(0,r.jsx)(e.p,{children:"æå®æ° chunk çåç§°ã"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" settings"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackChunkName: "settings" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './settings.js'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsxs)(e.p,{children:["æç»æä»¶åä»ç± ",(0,r.jsx)(e.a,{href:"/zh/config/output.html#outputchunkfilename",children:(0,r.jsx)(e.code,{children:"output.chunkFilename"})})," å³å®ã"]}),"\n",(0,r.jsxs)(e.h4,{id:"rspackfetchpriority",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackfetchpriority",children:"#"}),"rspackFetchPriority"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:'"low" | "high" | "auto"'})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackFetchPriority"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["为æå®ç卿坼å
¥è®¾ç½® ",(0,r.jsx)(e.a,{href:"https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/fetchPriority",rel:"noopener noreferrer",target:"_blank",children:(0,r.jsx)(e.code,{children:"fetchPriority"})}),"ãä¹å¯ä»¥éè¿ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"module.parser.javascript.dynamicImportFetchPriority"})," é项为ææå¨æå¯¼å
¥è®¾ç½®å
¨å±é»è®¤å¼ã"]}),"\n",(0,r.jsx)(e.p,{children:"ä¾å¦ï¼ä¸ºé¦å±å
³é®æ¨¡å设置è¾é«çè·åä¼å
级ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" hero"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackFetchPriority: "high" */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './hero.js'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackinclude",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackinclude",children:"#"}),"rspackInclude"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:"RegExp"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackInclude"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["å¨å¯¼å
¥è§£ææ¶å¹é
çæ£å表达å¼ãåªæå¹é
çæ¨¡å",(0,r.jsx)(e.strong,{children:"æä¼è¢«æå
"}),"ã"]}),"\n",(0,r.jsxs)(e.p,{children:["ä¾å¦ï¼åªå° ",(0,r.jsx)(e.code,{children:"./locales"})," ç®å½ä¸ç ",(0,r.jsx)(e.code,{children:".json"})," æä»¶çº³å
¥å¨æå¯¼å
¥ä¸ä¸æï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" messages"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackInclude: /\\.json$/ */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" `./locales/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"`"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsxs)(e.h4,{id:"rspackexclude",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackexclude",children:"#"}),"rspackExclude"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:"RegExp"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackExclude"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["å¨å¯¼å
¥è§£ææ¶å¹é
çæ£å表达å¼ãåªæå¹é
çæ¨¡å",(0,r.jsx)(e.strong,{children:"ä¸ä¼è¢«æå
"}),"ã"]}),"\n",(0,r.jsxs)(e.p,{children:["ä¾å¦ï¼æé¤ ",(0,r.jsx)(e.code,{children:"./locales"})," ç®å½ä¸çæµè¯æä»¶ï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" messages"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /* rspackExclude: /\\.test\\.js$/ */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" `./locales/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"language"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:".js`"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})})]})})}),"\n",(0,r.jsx)(l.Pq,{type:"info",title:"Info",children:(0,r.jsxs)(e.p,{children:["\n",(0,r.jsx)(e.code,{children:"rspackInclude"})," å ",(0,r.jsx)(e.code,{children:"rspackExclude"})," åªä¼çééæè·¯å¾åç¼ï¼ä¾å¦ ",(0,r.jsx)(e.code,{children:"./locales"}),"ï¼ä¸åç°çå鿍¡åï¼ä¸ä¼æ¹å该åç¼ãçä»·ç ",(0,r.jsx)(e.code,{children:"webpackInclude"})," å ",(0,r.jsx)(e.code,{children:"webpackExclude"})," 注éä¹ä¼è¢«å
¼å®¹æ¯æã"]}
1)}),"\n",(0,r.jsxs)(e.h4,{id:"rspackexports",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rspackexports",children:"#"}),"rspackExports"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"ç±»åï¼"})," ",(0,r.jsx)(e.code,{children:"string | string[]"})]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:"webpack å
¼å®¹åç§°ï¼"})," ",(0,r.jsx)(e.code,{children:"webpackExports"})]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["使 Rspack å¨å¤çè¯¥å¨æ ",(0,r.jsx)(e.code,{children:"import()"})," æ¨¡åæ¶ä»
æå
æå®ç导åºãè¿æ ·å¯ä»¥éä½ chunk ç产ç©ä½ç§¯ã"]}),"\n",(0,r.jsx)(e.p,{children:"ä¾å¦ï¼å½å¯¼å
¥ç»æä¼ ç»å
¶ä»å½æ°ãRspack æ æ³éææ¨æå
·ä½ä½¿ç¨äºåªäºå¯¼åºæ¶ï¼å¯ä»¥æ¾å¼å£°æéè¦ç导åºï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" widget"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" await"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:' /* rspackExports: ["render", "version"] */'})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './widget.js'"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"consumeWidget"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(widget);"})]})]})})}),"\n",(0,r.jsxs)(e.p,{children:["妿代ç ç´æ¥è®¿é®å¯¼å
¥æ¨¡åç屿§æå¯¹å
¶è¿è¡è§£æï¼Rspack é常å¯ä»¥èªå¨æ¨æä½¿ç¨ç导åºï¼æ éæ·»å ",(0,r.jsx)(e.code,{children:"rspackExports"}),"ã"]}),"\n",(0,r.jsxs)(e.h2,{id:"commonjs",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#commonjs",children:"#"}),"CommonJS"]}),"\n",(0,r.jsxs)(e.p,{children:["Rspack 乿¯æ ",(0,r.jsx)(e.code,{children:"CommonJS"})," è¯æ³ï¼å¯ä»¥ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"require"})," å ",(0,r.jsx)(e.code,{children:"module.exports"})," è¯æ³ã"]}),"\n",(0,r.jsxs)(e.h3,{id:"require",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#require",children:"#"}),"require"]}),"\n",(0,r.jsx)(e.p,{children:"ä»¥åæ¥çæ¹å¼å¼å
¥å
¶ä»æ¨¡åã"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(dependency: string);"})]})})})}),"\n",(0,r.jsxs)(e.h3,{id:"requireresolve",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#requireresolve",children:"#"}),"require.resolve"]}),"\n",(0,r.jsxs)(e.p,{children:["ä»¥åæ¥çæ¹å¼è·å模åç IDãæ¤æ¹æ³ä¼å°æ¨¡åæå
è¿æç»ç bundle ä¸ï¼ä½ä¸ä¼æ§è¡æ¨¡å代ç ãè¿åçæ¨¡å ID 主è¦ç¨äºä¸ ",(0,r.jsx)(e.code,{children:"require.cache[id]"})," æ Rspack å
é¨ç ",(0,r.jsx)(e.code,{children:"__webpack_require__(id)"})," ä¸èµ·ä½¿ç¨ï¼å¨å¤§å¤æ°åºç¨åºæ¯ä¸åºé¿å
ç´æ¥ä½¿ç¨æ¤æ¹æ³ã"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolve"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(dependency: string);"})]})})})}),"\n",(0,r.jsx)(l.Pq,{type:"warning",title:"Warning",children:(0,r.jsxs)(e.p,{children:["\n模å ID çç±»åå¯ä»¥æ¯ ",(0,r.jsx)(e.code,{children:"number"})," æ ",(0,r.jsx)(e.code,{children:"string"}),"ï¼å
·ä½åå³äº ",(0,r.jsx)(e.code,{children:"optimization.moduleIds"})," é
ç½®ã"]})}),"\n",(0,r.jsxs)(e.h3,{id:"requirecache",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#requirecache",children:"#"}),"require.cache"]}
1),"\n",(0,r.jsx)(e.p,{children:"å¤å¤å¼ç¨å䏿¨¡åï¼æç»åªä¼äº§ç䏿¬¡æ¨¡åæ§è¡å䏿¬¡å¯¼åºãæä»¥ï¼ä¼å¨è¿è¡æ¶ï¼runtimeï¼ä¸ä¼ä¿åä¸ä»½ç¼åãå 餿¤ç¼åï¼åä¼äº§çæ°çæ¨¡åæ§è¡åæ°ç导åºã"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"var"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" d1 "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'dependency'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'dependency'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"==="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" d1;"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"delete"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".cache["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolve"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'dependency'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")];"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'dependency'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"!=="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" d1;"})]})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"requirecontext",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#requirecontext",children:"#"}),"require.context"]}),"\n",(0,r.jsx)(c.a,{specific:["Rspack","Webpack"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"require.context"})," å
è®¸ä½ å¨æå° require ä¸ç»æ¨¡åã"]}),"\n",(0,r.jsxs)(e.p,{children:["ä½ å¯ä»¥å¨ä»£ç ä¸ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"require.context"}),"ï¼Rspack å°å¨æå»ºæ¶è¿è¡è§£æå¹¶å¼ç¨å¹é
çæ¨¡åã"]}),"\n",(0,r.jsx)(l.Pq,{type:"tip",title:"Tip",children:(0,r.jsxs)(e.p,{children:["\n",(0,r.jsx)(e.code,{children:"require.context"})," çè¿åå¼ä¸ ",(0,r.jsx)(e.a,{href:"/zh/api/runtime-api/module-variables.html#importmetawebpackcontext",children:"import.meta.webpackContext"})," ç¸åã"]})}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"ç±»åï¼"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" requireContext"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * è¦æç´¢çç®å½"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" directory"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * æ¯å¦è¿æç´¢å
¶åç®å½"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"@default"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" true"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" includeSubdirs"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" boolean"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * å¹é
æä»¶çæ£å表达å¼"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"@default"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /^\\.\\/.*$/ï¼å¹é
ä»»ææä»¶ï¼"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" filter"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" RegExp"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * 模åå 载模å¼"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"@default"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" '"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"sync"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"'"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mode"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'sync'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" |"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'eager'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" |"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'weak'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" |"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'lazy'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" |"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'lazy-once'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" Context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})]})})}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"示ä¾ï¼"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å建ä¸ä¸ªä¸ä¸æï¼"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// æä»¶ç´æ¥æ¥èª test ç®å½ï¼å¹é
çæä»¶å以 `.test.js` ç»å°¾ã"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'./test'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" false"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /\\.test\\.js"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})]})})}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å建ä¸ä¸ªä¸ä¸æï¼"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// æä»¶æ¥èªç¶æä»¶å¤¹åå
¶ææå级æä»¶å¤¹ï¼å¹é
çæä»¶å以 `.stories.js` ç»å°¾ã"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'../'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" true"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /\\.stories\\.js"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})]})})}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// 妿 `mode` 被设置为 `lazy`ï¼æ¨¡åå°ä¼è¢«å¼æ¥å è½½"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'./locales'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" true"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /\\.json"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'lazy'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})]})})}),"\n",(0,r.jsxs)(l.Pq,{type:"tip",title:"Tip",children:[(0,r.jsxs)(e.p,{children:["\nRspack å¨ç¼è¯æ¶ï¼ä¼éè¿éæåææ¥è§£æ ",(0,r.jsx)(e.code,{children:"require.context"})," çåæ°ï¼å æ¤åæ°å¿
é¡»æ¯",(0,r.jsx)(e.a,{href:"https://developer.mozilla.org/en-US/docs/Glossary/Literal",rel:"noopener noreferrer",target:"_blank",children:"åé¢é"}),"ã"]}),(0,r.jsxs)(e.p,{children:["ä¾å¦ï¼",(0,r.jsx)(e.code,{children:"filter"})," çå¼ä¸å
è®¸ä¼ å
¥ä¸ä¸ªåéï¼ä¹ä¸å
è®¸ä¼ å
¥ ",(0,r.jsx)(e.code,{children:"new RegExp()"})," çæçå¼ï¼åªè½æ¯ä¸ä¸ªæ£å表达å¼åé¢éã"]})]}),"\n",(0,r.jsxs)(e.h3,{id:"requireensure",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#requireensure",children:"#"}),"require.ensure"]}),"\n",(0,r.jsx)(c.a,{specific:["Rspack","Webpack"]}),"\n",(0,r.jsx)(l.Pq,{type:"tip",title:"Tip",children:(0,r.jsxs)(e.p,{children:["\nå»ºè®®ä½¿ç¨æ´ç¬¦åæ åç ",(0,r.jsx)(e.code,{children:"import()"})," æ¥æ¿ä»£ ",(0,r.jsx)(e.code,{children:"require.ensure()"}),"ã"]})}),"\n",(0,r.jsxs)(e.p,{children:["å°ç»å® ",(0,r.jsx)(e.code,{children:"dependencies"})," åç¬æå
ï¼å¹¶å¼æ¥å è½½è¿äºä¾èµã"]}),"\n"
1,(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"Type:"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" requireEnsure"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * éè¦å¼æ¥å è½½çæ¨¡åå表"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" dependencies"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" String"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"[]"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * å½ dependencies ä¸ç模åé½å è½½å®æ¯æ¶ï¼è¿ä¸ªå½æ°å°±ä¼è¢«æ§è¡ã"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * å¨è¿ä¸ªå½æ°ä¸ä¹å¯ä»¥è¿ä¸æ¥ä½¿ç¨ require() æ¥å 载模åã"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"}
1,children:" callback"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"()"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * å½å è½½ä¾èµå¤±è´¥çæ¶åæ§è¡ç彿°"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" errorCallback"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"error"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" /**"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * æå®ç± require.ensure() çæç chunk åç§°ã"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * éè¿æå®ç¸åç chunkName æ¥åå¹¶å¤ä¸ª require.ensure() è°ç¨ç代ç ï¼ä»èåªçæä¸ä¸ª bundleï¼"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" * ä»èåå°æµè§å¨å è½½çæ¬¡æ°ã"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" */"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" chunkName"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" string"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" Context"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})]})})}),"\n",(0,r.jsx)(l.Pq,{type:"warning",title:"Warning",children:(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["è¯¥ç¹æ§å
é¨ä¾èµäº ",(0,r.jsx)(e.a,{href:"https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise",rel:"noopener noreferrer",target:"_blank",children:"Promise"}),"ã å¦æä½ å¨æ§çæµè§å¨ä¸ä½¿ç¨ ",(0,r.jsx)(e.code,{children:"require.ensure"}),"ï¼ æå¥½å å
¥ polyfill ",(0,r.jsx)(e.a,{href:"https://github.com/stefanpenner/es6-promise",rel:"noopener noreferrer",target:"_blank",children:"es6-promise"})," æ ",(0,r.jsx)(e.a,{href:"https://github.com/taylorhakes/promise-polyfill",rel:"noopener noreferrer",target:"_blank",children:"promise-polyfill"}),"ã"]}),"\n",(0,r.jsx)(e.li,{children:"å webpack 䏿 ·ï¼callback 彿°ä¹å¯ä»¥æ¥æ¶ä¸ä¸ªå为 require çåæ°ï¼ä¸å¿
é¡»å为 requireï¼ï¼è¯¥ require åæ°å cjs ç require å
¨å±åéä¸è´ï¼ä½æä»¬å»ºè®®ç´æ¥ä½¿ç¨å
¨å±ç require æ¥å 载模åè䏿¯è¯¥ require åæ°ï¼å 为 loader å¯è½ä¼å°å
¶éå½å导è´ä¾èµåæå¤±è´¥ã"}),"\n"]})}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"Example:"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"var"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" a "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'normal-dep'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"module"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".hot) {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".ensure"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'b'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"]"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" function"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" () {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" var"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" c "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'c'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // Do something special..."})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" });"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"requireresolveweak",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#requireresolveweak",children:"#"}),"require.resolveWeak"]}),"\n",(0,r.jsx)(c.a,{specific:["Rspack","Webpack"]}),"\n",(0,r.jsxs)(e.p,{children:["ä¸ ",(0,r.jsx)(e.code,{children:"require.resolve"}),' 类似ï¼ä½æ¯ä¸ä¼æ module æå
å°æç»ç bundle ä¸ãæ¯ "å¼±ï¼weakï¼" ä¾èµã']}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolveWeak"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"(dependency: string);"})]})})})}),"\n",(0,r.jsx)(e.p,{children:"示ä¾ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" (__webpack_modules__["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolveWeak"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'module'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")]) {"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // 彿¨¡åå¯ç¨æ¶ï¼æ§è¡ä¸äºæä½"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:".cache["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolveWeak"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'module'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")]) {"})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // 卿¨¡åå è½½å®æä¹åï¼æ§è¡ä¸äºæä½"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})}),"\n",(0,r.jsx)(e.span,{className:"line"}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"}
1,children:"// ä½ å¯ä»¥åæ§è¡å
¶ä» require/import æ¹æ³ä¸æ ·ï¼"})}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:'// æ§è¡å¨æè§£æä¸ä¸æ resolves ("context")'})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" page"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'Foo'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"__webpack_modules__["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".resolveWeak"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"`./page/"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"${"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"page"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"}"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"`"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:")];"})]})]})})}),"\n",(0,r.jsxs)(e.h2,{id:"data-uri-模å",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#data-uri-模å",children:"#"}),"Data URI 模å"]}),"\n",(0,r.jsxs)(e.p,{children:["Rspack æ¯æä½¿ç¨ ",(0,r.jsx)(e.code,{children:"import"})," å ",(0,r.jsx)(e.code,{children:"require"})," è¯æ³å¯¼å
¥ Data URI 模åã"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"import"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" DataURI "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'data:text/javascript,export default 42'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:";"})]})})})}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.strong,{children:"require"})}),"\n"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsx)(e.code,{children:(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'data:text/javascript,module.exports = 42'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})})})}),"\n",(0,r.jsx)(e.p,{children:"餿¤ä¹å¤ï¼è¿æ¯æäº Base64 ç¼ç ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" number"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" fn"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"} "}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" require"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0='"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:");"})]})]})})}),"\n",(0,r.jsx)(l.Pq,{type:"tip",title:"Tip",children:(0,r.jsx)(e.p,{children:"\nData URI 模åå¯ä»¥è¢«ç¨ä½èææ¨¡åï¼Virtual Modulesï¼çå®ç°æ¹å¼ï¼å¦ï¼é
å loader 宿è¿è¡æ¶å¨æå è½½èªå®ä¹æ¨¡åã"})}),"\n",(0,r.jsxs)(e.h3,{id:"å
ç½®-rules",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#å
ç½®-rules",children:"#"}),"å
ç½® Rules"]}),"\n",(0,r.jsxs)(e.p,{children:["Rspack é»è®¤æ¯æè¿äº ",(0,r.jsx)(e.a,{href:"https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Guides/MIME_types",rel:"noopener noreferrer",target:"_blank",children:"MIME ç±»å"})," ç data URI 模åï¼",(0,r.jsx)(e.code,{children:"application/json"}),"ã",(0,r.jsx)(e.code,{children:"text/javascript"}),"ã",(0,r.jsx)(e.code,{children:"application/javascript"}),"ã",(0,r.jsx)(e.code,{children:"application/node"})," å ",(0,r.jsx)(e.code,{children:"application/wasm"}),"ãè¿æå³çå½ä½ 使ç¨è¿äº MIME ç±»åå建 data URI æ¨¡åæ¶ï¼Rspack ä¼èªå¨è¯å«ä»ä»¬ã"]}),"\n",(0,r.jsx)(e.p,{children:"Rspack å
ç½®ç MIME rules å¦ä¸ï¼"}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" defaultMimeRules"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mimetype"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'application/node'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" type"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'javascript/auto'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mimetype"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'application/json'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" type"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'json'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mimetype"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" or"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'text/javascript'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'application/javascript'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"]"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" type"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'javascript/esm'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // ..."})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mimetype"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'application/wasm'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" type"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'webassembly/async'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // ..."})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"];"})})]})})}),"\n",(0,r.jsxs)(e.h3,{id:"èªå®ä¹-rules",children:[(0,r.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#èªå
1®ä¹-rules",children:"#"}),"èªå®ä¹ Rules"]}),"\n",(0,r.jsxs)(e.p,{children:["ä½ å¯ä»¥ä¹ä½¿ç¨ ",(0,r.jsx)(e.a,{href:"/zh/config/module-rules.html#rulesmimetype",children:"rules[].mimetype"})," æ¥æ©å± Data URI 模åçå¹é
è§åï¼ä¾å¦ä¸º ",(0,r.jsx)(e.code,{children:"text/javascript"})," æ·»å èªå®ä¹ç loadersï¼"]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"rspack.config.mjs",lang:"js",children:(0,r.jsxs)(e.code,{children:[(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" module"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" rules"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" mimetype"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'text/javascript'"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" use"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" // ..."})}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ]"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ]"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(e.span,{className:"line",children:[(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(e.span,{className:"line",children:(0,r.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,r.jsx)(o.A,{url:"https://webpack.docschina.org/api/module-methods/"})]})}function h(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:e}={...(0,i.R)(),...s.components};return e?(0,r.jsx)(e,{...s,children:(0,r.jsx)(a,{...s})}):a(s)}h.__RSPRESS_PAGE_META={},h.__RSPRESS_PAGE_META["zh%2Fapi%2Fruntime-api%2Fmodule-methods.mdx"]={toc:[{id:"es-modules-æ¨è",text:"ES modules (æ¨è)",depth:2},{id:"import",text:"import",depth:3},{id:"export",text:"export",depth:3},{id:"dynamic-import",text:"Dynamic import()",depth:3},{id:"import-ä¸çå¨æè¡¨è¾¾å¼",text:"import() ä¸çå¨æè¡¨è¾¾å¼",depth:3},{id:"magic-comments",text:"import() ä¸çéæ³æ³¨é",depth:3},{id:"rspackignore",text:"rspackIgnore",depth:4},{id:"rspackmode",text:"rspackMode",depth:4},{id:"rspackprefetch",text:"rspackPrefetch",depth:4},{id:"rspackpreload",text:"rspackPreload",depth:4},{id:"rspackchunkname",text:"rspackChunkName",depth:4}
1,{id:"rspackfetchpriority",text:"rspackFetchPriority",depth:4},{id:"rspackinclude",text:"rspackInclude",depth:4},{id:"rspackexclude",text:"rspackExclude",depth:4},{id:"rspackexports",text:"rspackExports",depth:4},{id:"commonjs",text:"CommonJS",depth:2},{id:"require",text:"require",depth:3},{id:"requireresolve",text:"require.resolve",depth:3},{id:"requirecache",text:"require.cache",depth:3},{id:"requirecontext",text:"require.context",depth:3},{id:"requireensure",text:"require.ensure",depth:3},{id:"requireresolveweak",text:"require.resolveWeak",depth:3},{id:"data-uri-模å",text:"Data URI 模å",depth:2},{id:"å
ç½®-rules",text:"å
ç½® Rules",depth:3},{id:"èªå®ä¹-rules",text:"èªå®ä¹ Rules",depth:3}],title:"æ¨¡åæ¹æ³",headingTitle:"æ¨¡åæ¹æ³",frontmatter:{description:"å½ä½¿ç¨ Rspack æå
åºç¨ç¨åºæ¶ï¼ä½ å¯ä»¥éæ©å¤ç§æ¨¡åè¯æ³é£æ ¼ï¼å
æ¬ ES modules å CommonJSã"}},n.d(e,{default:()=>h})},yW(s,e,n){var r,i=n("i"),l=n("NC"),o=n("V"),c=n("mT"),a=((r={}).Deprecated="Deprecated",r.Removed="Removed",r.Experimental="Experimental",r);function h(s){let e,n=(0,l.u)(),r=`/${n}/misc/planning/future`,a=s.inline?c.A.tagInline:c.A.tag,h=s.inline?c.A.wrapperInline:c.A.wrapper;return(0,i.jsxs)("div",{className:`${h} rp-not-doc`,children:[s.addedVersion&&(0,i.jsx)("span",{className:`${a} ${c.A.added}`,children:(0,i.jsxs)(o.N_,{href:(e=s.addedVersion,`https://github.com/web-infra-dev/rspack/releases/tag/v${e.replace("v","")}`),children:["Added in v",s.addedVersion]})}),s.deprecatedVersion&&(0,i.jsx)("span",{className:`${a} ${c.A.deprecated}`,children:(0,i.jsxs)(o.N_,{href:r,children:["Deprecated in v",s.deprecatedVersion]})}),s.removedVersion&&(0,i.jsx)("span",{className:`${a} ${c.A.removed}`,children:(0,i.jsxs)(o.N_,{href:r,children:["Removed in v",s.removedVersion]})}),s.stability&&(0,i.jsxs)("div",{className:`${a} ${s.stability?c.A[s.stability.toLowerCase()]:""}`,children:["Stability: ",s.stability]}),s.specific&&s.specific.length>0&&(0,i.jsxs)("span",{className:`${a} ${c.A.specific}`,children:[s.specific.join("/")," ",s.specific.length>1?"specific":"only"]})]})}n.d(e,{a:()=>h,k:()=>a})},sX(s,e,n){var r=n("i"),i=n("NC"),l=n("V");let o="https://creativecommons.org/licenses/by/4.0/",c={borderTop:"1px solid var(--rp-c-divider-light)",color:"var(--rp-c-text-2)",fontSize:"13px",marginTop:"48px",paddingTop:"16px"};e.A=s=>{let{url:e}=s;return"en"===(0,i.u)()?(0,r.jsxs)("p",{style:c,children:["This page is adapted from ",(0,r.jsx)(l.N_,{href:e,children:"webpack documentation"})," ","under the ",(0,r.jsx)(l.N_,{href:o,children:"CC BY 4.0"}),", with modifications."]}):(0,r.jsxs)("p",{style:c,children:["æ¬é¡µæ¹ç¼èª ",(0,r.jsx)(l.N_,{href:e,children:"webpack ææ¡£"}),"ï¼éµå¾ª"," ",(0,r.jsx)(l.N_,{href:o,children:"CC BY 4.0"}),"ï¼ä¸å·²ä½ä¿®æ¹ã"]})}}}]);
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.