PageSourceSearch

https://rsbuild.rs/static/js/async/route-27bfb71271ad.fe850fce0e.js

js rsbuild.rs collected 2026-09-25 14:11:32 UTC 5,616 bytes, 1 lines download raw bytes

1"use strict";(self.rspackChunkrsbuild_website=self.rspackChunkrsbuild_website||[]).push([["8a"],{Uo(s,r,e){e.r(r);var n=e("E"),i=e("H"),o=e("x");function l(s){let r={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,i.R)(),...s.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(r.h1,{id:"root",children:[(0,n.jsx)(r.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#root",children:"#"}),"root"]}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.strong,{children:"类型:"})," ",(0,n.jsx)(r.code,{children:"string"})]}),"\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.strong,{children:"默认值:"})," ",(0,n.jsx)(r.a,{href:"https://nodejs.org/api/process.html#processcwd",rel:"noopener noreferrer",target:"_blank",children:"process.cwd()"})]}),"\n"]}),"\n",(0,n.jsxs)(r.p,{children:["指定项目根目录。可以是绝对路径,也可以是相对于 ",(0,n.jsx)(r.code,{children:"process.cwd()"})," 的路径。"]}),"\n",(0,n.jsxs)(r.p,{children:["Rsbuild ",(0,n.jsx)(r.code,{children:"root"})," 的值也会传递给 Rspack 的 ",(0,n.jsx)(r.a,{href:"https://rspack.rs/zh/config/context",rel:"noopener noreferrer",target:"_blank",children:"context"})," 配置。"]}),"\n",(0,n.jsxs)(o.Pq,{type:"tip",title:"Tip",children:[(0,n.jsxs)(r.p,{children:["\n",(0,n.jsx)(r.code,{children:"root"})," 的值不会影响 ",(0,n.jsx)(r.code,{children:".env"})," 文件的加载路径,因为 ",(0,n.jsx)(r.code,{children:".env"})," 文件早于 Rsbuild 的配置文件被解析。"]}),(0,n.jsxs)(r.p,{children:["Rsbuild CLI 支持使用 ",(0,n.jsx)(r.code,{children:"--root"})," 选项来指定根目录,它可以影响 ",(0,n.jsx)(r.code,{children:".env"})," 文件的加载路径,详见 ",(0,n.jsx)(r.a,{href:"/zh/guide/basic/cli.html",children:'"CLI"'}),"。"]})]}),"\n",(0,n.jsxs)(r.h2,{id:"示例",children:[(0,n.jsx)(r.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#示例",children:"#"}),"示例"]}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:"相对路径:"}),"\n"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(r.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"rsbuild.config.ts",lang:"ts",children:(0,n.jsxs)(r.code,{children:[(0,n.jsxs)(r.span,{className:"line",children:[(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(r.span,{className:"line",children:[(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:"  root"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-string-expression)"},children:" './foo'"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(r.span,{className:"line",children:(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:"绝对路径:"}),"\n"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(r.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"rsbuild.config.ts",lang:"ts",children:(0,n.jsxs)(r.code,{children:[(0,n.jsxs)(r.span,{className:"line",children:[(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:" { join } "}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'node:path'"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:";"})]}),"\n",(0,n.jsx)(r.span,{className:"line"}),"\n",(0,n.jsxs)(r.span,{className:"line",children:[(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:" default"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(r.span,{className:"line",children:[(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:"  root"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-function)"},children:" join"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:"(__dirname"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-string-expression)"},children:" 'foo'"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:")"}),(0,n.jsx)(r.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsx)(r.span,{className:"line",children:(0,n.jsx)(r.span,{style:{color:"var(--shiki-foreground)"},children:"};"})})]})})})]})}function c(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:r}={...(0,i.R)(),...s.components};return r?(0,n.jsx)(r,{...s,children:(0,n.jsx)(l,{...s})}):l(s)}c.__RSPRESS_PAGE_META={},c.__RSPRESS_PAGE_META["zh%2Fconfig%2Froot.mdx"]={toc:[{id:"示例",text:"示例",depth:2}],title:"root",headingTitle:"root",frontmatter:{description:"指定项目根目录。可以是绝对路径,也可以是相对于 process.cwd() 的路径。"}},e.d(r,{default:()=>c})}}]);

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.