1"use strict";(self.rspackChunkrspack_website=self.rspackChunkrspack_website||[]).push([[79],{wv(s,e,r){r.r(e);var n=r("i"),i=r("f");function l(s){let e={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",...(0,i.R)(),...s.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.h1,{id:"typescript",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#typescript",children:"#"}),"TypeScript"]}),"\n",(0,n.jsxs)(e.h2,{id:"å¦ä½ä½¿ç¨",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#å¦ä½ä½¿ç¨",children:"#"}),"å¦ä½ä½¿ç¨"]}),"\n",(0,n.jsxs)(e.p,{children:["éè¿ ",(0,n.jsx)(e.a,{href:"/zh/guide/features/builtin-swc-loader.html",children:(0,n.jsx)(e.code,{children:"builtin:swc-loader"})})," å¯ä»¥å¼å¯å¯¹ TypeScript çæ¯æã"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.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,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" module"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" rules"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" test"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /\\.(?:js"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"mjs"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"ts)"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" exclude"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/node_modules/"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"]"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" loader"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'builtin:swc-loader'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" options"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" detectSyntax"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'auto'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ]"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,n.jsxs)(e.h2,{id:"ä»
转è¯transpile-only",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#ä»
转è¯transpile-only",children:"#"}),"ä»
转è¯ï¼transpile onlyï¼"]}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"builtin:swc-loader"})," ä»
ä¼å¯¹æºç è¿è¡è½¬è¯ï¼å æ¤ä½ éè¦ä½¿ç¨å
¶ä»å·¥å
·ï¼å¦ï¼tscï¼å®æå¯¹æºç çç±»åæ£æ¥ã"]}),"\n",(0,n.jsxs)(e.h2,{id:"å¼å¯-isolatedmodules",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#å¼å¯-isolatedmodules",children:"#"}),"å¼å¯ isolatedModules"]}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"builtin:swc-loader"})," ä¼ä¸ºæ¯ä¸ä¸ªæ¨¡ååå¼è½¬è¯ï¼è¿éè¦å¼å¯ ",(0,n.jsx)(e.a,{href:"https://www.t
1ypescriptlang.org/tsconfig#isolatedModules",rel:"noopener noreferrer",target:"_blank",children:(0,n.jsx)(e.code,{children:"isolatedModules"})})," ä¿è¯ tsc 对æºä»£ç çç±»åæ ¡éªã\nèæä¸äºåè½ï¼å¦ ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/enums.html#const-enums",rel:"noopener noreferrer",target:"_blank",children:"const enums"})," 忝ä¾èµäºå¯¹æ´ä¸ªé¡¹ç®çåæï¼å æ¤ï¼è¿äºåè½å°æ æ³ä½¿ç¨ãæ¨èæ¾å¼å°å¨ ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," ä¸å¼å¯è¿ä¸ªé项ï¼ä»¥ä½¿å¾ Rspack çæ¨¡åå¤çè¡ä¸ºä¸ IDE æç¤ºæç±»åæ£æ¥ä¸ä¿æä¸è´ã"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"tsconfig.json",lang:"json",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"{"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:' "compilerOptions"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:' "isolatedModules"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" true"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,n.jsxs)(e.h2,{id:"ç±»åæ£æ¥",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#ç±»åæ£æ¥",children:"#"}),"ç±»åæ£æ¥"]}),"\n",(0,n.jsxs)(e.p,{children:["ä½ å¯ä»¥ä½¿ç¨ ",(0,n.jsx)(e.a,{href:"https://github.com/rstackjs/ts-checker-rspack-plugin",rel:"noopener noreferrer",target:"_blank",children:"ts-checker-rspack-plugin"})," å¨ç¼è¯è¿ç¨ä¸æ§è¡ TypeScript ç±»åæ£æ¥ãç¶èï¼éè¦æ³¨æçæ¯ï¼ç¹å«æ¯å¯¹äºè¾å¤§ç项ç®ï¼TypeScript çç±»åæ£æ¥å¯è½éå¸¸èæ¶ãè¿æå³çç±»åæ£æ¥æéçæ¶é´å¯è½è¶
è¿ Rspack æ¬èº«çæå»ºæ¶é´ã"]}),"\n",(0,n.jsx)(e.p,{children:"å¦æä½ å¨å¼å模å¼ä¸ä½¿ç¨è¯¥æä»¶ï¼å®å°ä¸ä¼é»å¡æå»ºè¿ç¨ï¼ä½ å¯ä»¥ç»§ç»è¿è¡æå»ºã使¯ï¼å¨æå»ºæ¨¡å¼ä¸ï¼è¯¥æä»¶å°ä¼é»å¡æå»ºï¼ç´å°ç±»åæ£æ¥å®æï¼æä»¥å¯è½ä¼å¯¼è´æå»ºæ¶é´åé¿ã"}),"\n",(0,n.jsx)(e.p,{children:"æ ¹æ®ä½ çå®é
éæ±ï¼ä½ åºè¯¥å³å®æ¯å¦å¯ç¨è¯¥æä»¶ãå¦æç±»åæ£æ¥è¿ç¨æä¸ºæå»ºè¿ç¨çç¶é¢ï¼æä»¬å»ºè®®ä½¿ç¨ TypeScript çå¢éæå»ºåè½ã该åè½å¯ä»¥éè¿ä»
åæèªä¸æ¬¡æå»ºä»¥æ¥ä¿®æ¹çæä»¶æ¥å¤§å¤§å å¿«ç±»åæ£æ¥çé度ã"}),"\n",(0,n.jsxs)(e.p,{children:["è¦å¯ç¨ TypeScript çå¢éæå»ºï¼ä½ å¯ä»¥å¨ç¬ç«ä½¿ç¨ ",(0,n.jsx)(e.code,{children:"tsc --incremental"})," æè
卿件é",(0,n.jsx)(e.a,{href:"https://github.com/rstackjs/ts-checker-rspack-plugin#enabling-incremental-mode",rel:"noopener noreferrer",target:"_blank",children:"ä½¿ç¨ incremental mode"}),"ã"]}),"\n",(0,n.jsx)(e.p,{children:"å¯ç¨å¢éæå»ºå¯ä»¥å¸®å©åå°ç±»åæ£æ¥çæ¶é´ï¼ç¹å«æ¯å½åªæå°æ°æä»¶è¢«ä¿®æ¹æ¶ãè¿æ ·ï¼ä½ å¯ä»¥å¨ä¼åæå»ºè¿ç¨çåæ¶ï¼ä¸ä¼æå¤±ç±»åæ£æ¥ç好å¤ã"}),"\n",(0,n.jsx)(e.p,{children:"请记ä½ï¼å¨ä½ çå
·ä½é¡¹ç®ä¸ï¼éè¦æè¡¡æå»ºé度åç±»åæ£æ¥åç¡®æ§ä¹é´çæè¡¡ï¼å¹¶æ®æ¤éæ©æä½³æ¹æ³ã"}),"\n",(0,n.jsxs)(e.h2,{id:"jsxtsx",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#jsxtsx",children:"#"}),"JSX/TSX"]}),"\n",(0,n.jsxs)(e.p,{children:["éè¿ ",(0,n.jsx)(e.a,{href:"/zh/guide/features/builtin-swc-loader.html",children:(0,n.jsx)(e.code,{children:"builtin:swc-loader"})})," å¯ä»¥å¼å¯å¯¹ JSX å TSX çæ¯æã"]}
1),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.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,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" module"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" rules"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" test"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" /\\.(?:js"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"mjs"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"jsx"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"ts"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"tsx)"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"$"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"/"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" use"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" loader"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'builtin:swc-loader'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" options"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" detectSyntax"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'auto'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" jsc"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" transform"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" react"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" pragma"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'React.createElement'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" pragmaFrag"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'React.Fragment'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" throwIfNamespace"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" true"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" development"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" false"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ]"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,n.jsxs)(e.h2,{id:"alias",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#alias",children:"#"}),"Alias"]}),"\n",(0,n.jsxs)(e.p,{children:["ç¹å» ",(0,n.jsx)(e.a,{href:"/zh/config/resolve.html#resolvetsconfig",children:"resolve.tsConfig"})," æ¥ç详æ
ã"]}
1),"\n",(0,n.jsxs)(e.h2,{id:"client-ç±»å",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#client-ç±»å",children:"#"}),"Client ç±»å"]}),"\n",(0,n.jsxs)(e.p,{children:["å¨ TypeScript 代ç ä¸ï¼å¯ä»¥è·åå° Rspack ç¹æçåè½ï¼ä¾å¦ ",(0,n.jsx)(e.a,{href:"/zh/api/runtime-api/module-variables.html#importmetaglob",children:"import.meta.glob"}),"ã"]}),"\n",(0,n.jsxs)(e.p,{children:["Rspack éè¿ ",(0,n.jsx)(e.code,{children:"@rspack/core/module"})," æä¾ Client 模åçç±»åï¼ä½ å¯ä»¥éè¿ä¸åæ¹æ³æ¥å£°æå®ä»¬ï¼"]}),"\n",(0,n.jsxs)(e.ol,{children:["\n",(0,n.jsxs)(e.li,{children:["\n",(0,n.jsx)(e.p,{children:"æ·»å TypeScript reference æä»¤æ¥å£°æï¼"}),"\n",(0,n.jsx)(e.p,{children:"å¨å
¨å±ç d.ts 声ææä»¶ä¸æ·»å 以ä¸å
容ï¼"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"src/app-env.d.ts",lang:"ts",children:(0,n.jsx)(e.code,{children:(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"/// <"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"reference"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" types"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@rspack/core/module"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:" />"})]})})})}),"\n",(0,n.jsx)(e.p,{children:"ç¶å便å¯ä»¥å¨ä»»æ TypeScript æä»¶ä¸ä½¿ç¨ï¼"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"src/index.ts",lang:"ts",children:(0,n.jsx)(e.code,{children:(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"const"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:" modules"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" ="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:" import"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"meta"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:".glob"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'./dir/*.js'"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"); "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// å¦ææ²¡æä¸é¢çå¼ç¨å£°æï¼TypeScript å°ä¼æåºé误"})]})})})}),"\n"]}),"\n",(0,n.jsxs)(e.li,{children:["\n",(0,n.jsxs)(e.p,{children:["ä½ ä¹å¯ä»¥å° ",(0,n.jsx)(e.code,{children:"@rspack/core/module"})," æ·»å å° tsconfig.json ç ",(0,n.jsx)(e.code,{children:"types"})," åæ®µä¸ãå
·ä½å¯åè ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/tsconfig/#types",rel:"noopener noreferrer",target:"_blank",children:"tsconfig types ææ¡£"}),"ã"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"tsconfig.json",lang:"json",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"{"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:' "compilerOptions"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:' "types"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@rspack/core/module"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"]"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n"]}),"\n"]})]})}function o(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:e}={...(0,i.R)(),...s.components};return e?(0,n.jsx)(e,{...s,children:(0,n.jsx)(l,{...s})}):l(s)}o.__RSPRESS_PAGE_META={},o.__RSPRESS_PAGE_META["zh%2Fguide%2Flanguages%2Ftypescript.mdx"]={toc:[{id:"å¦ä½ä½¿ç¨",text:"å¦ä½ä½¿ç¨",depth:2},{id:"ä»
转è¯transpile-only",text:"ä»
转è¯ï¼transpile onlyï¼",depth:2},{id:"å¼å¯-isolatedmodules",text:"å¼å¯ isolatedModules",depth:2},{id:"ç±»åæ£æ¥",text:"ç±»åæ£æ¥",depth:2},{id:"jsxtsx",text:"JSX/TSX",depth:2},{id:"alias",text:"Alias",depth:2},{id:"client-ç±»å",text:"Client ç±»å",depth:2}],title:"TypeScript",headingTitle:"TypeScript",frontmatter:{description:"å¨ Rspack ä¸ä½¿ç¨TypeScriptçæåï¼æ¶µçç¯å¢é
ç½®ãéææ¹å¼ãè°è¯è¦ç¹ãå¼å模å¼ä¸å¸¸è§é®é¢å¤çã"}},r.d(e,{default:()=>o})}}]);
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.