Skip to content

Commit

Permalink
docs: add base version range
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Oct 2, 2024
1 parent c681381 commit 3ea5da7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions website/docs/en/config/dev/asset-prefix.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dev.assetPrefix

- **Type:** `boolean | string | 'auto'`
- **Default:** [`server.base`](/config/server/base)
- **Default:** [server.base](/config/server/base)

Set the URL prefix of static assets in [development mode](/config/mode).

Expand All @@ -15,7 +15,7 @@ The default value of `dev.assetPrefix` is the same as [server.base](/config/serv

When `server.base` is `/foo`, `index.html` and other static assets can be accessed through `http://localhost:3000/foo/`.

It should be noted that when customizing the `dev.assetPrefix` option, if you want static assets to be normally accessible through the Rsbuild dev server, `dev.assetPrefix` should contain the same url prefix as `server.base`, such as:
It should be noted that when customizing the `dev.assetPrefix` option, if you want static assets to be normally accessible through the Rsbuild dev server, `dev.assetPrefix` should contain the same URL prefix as `server.base`, such as:

```ts
export default {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/config/output/asset-prefix.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# output.assetPrefix

- **Type:** `string | 'auto'`
- **Default:** [`server.base`](/config/server/base)
- **Default:** [server.base](/config/server/base)

In [production mode](/config/mode), use this option to set the URL prefix for static assets, such as setting it to a CDN URL.

Expand Down Expand Up @@ -54,7 +54,7 @@ The default value of `output.assetPrefix` is the same as [server.base](/config/s

When `server.base` is `/foo`, `index.html` and static assets can be accessed through `http://localhost:3000/foo/`.

It should be noted that when customizing the `output.assetPrefix` option, if you want static assets to be accessible normally during [Rsbuild preview](/guide/basic/cli#rsbuild-preview), `output.assetPrefix` should contain the same url prefix as `server.base`, such as:
It should be noted that when customizing the `output.assetPrefix` option, if you want static assets to be accessible normally during [Rsbuild preview](/guide/basic/cli#rsbuild-preview), `output.assetPrefix` should contain the same URL prefix as `server.base`, such as:

```ts
export default {
Expand Down
9 changes: 5 additions & 4 deletions website/docs/en/config/server/base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- **Type:** `string`
- **Default:** `/`
- **Version:** `>= 1.0.10`

`server.base` is used to configure the [base path](/guide/basic/server#base-path) of the server.

Expand Down Expand Up @@ -29,18 +30,18 @@ When `server.base` is `/foo`, the default resource URL loaded in the browser is
<script defer src="/foo/static/js/index.js"></script>
```

Then, `index.html` and static asset outputs can be accessed through `http://localhost:3000/foo/`.
Then, `index.html` and static assets can be accessed through `http://localhost:3000/foo/`.

If you do not want to use this default behavior, you can override it by explicitly setting `dev.assetPrefix` / `output.assetPrefix` :

```ts
export default {
output: {
assetPrefix: '/',
},
dev: {
assetPrefix: '/',
},
output: {
assetPrefix: 'https://cdn.example.com/assets/',
},
server: {
base: '/foo',
},
Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/config/dev/asset-prefix.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dev.assetPrefix

- **类型:** `boolean | string | 'auto'`
- **默认值:** [`server.base`](/config/server/base)
- **默认值:** [server.base](/config/server/base)

设置 [开发模式](/config/mode) 下的静态资源 URL 前缀。

Expand All @@ -15,7 +15,7 @@

`server.base``/foo` 时,可通过 `http://localhost:3000/foo/` 访问到 `index.html` 及其他静态资源产物。

需要注意的是,当自定义 `dev.assetPrefix` 选项时,如果希望静态资源能够通过 Rsbuild 开发服务器正常访问到,`dev.assetPrefix` 应和 `server.base` 包含相同的 url 前缀,如:
需要注意的是,当自定义 `dev.assetPrefix` 选项时,如果希望静态资源能够通过 Rsbuild 开发服务器正常访问到,`dev.assetPrefix` 应和 `server.base` 包含相同的 URL 前缀,如:

```ts
export default {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/config/output/asset-prefix.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# output.assetPrefix

- **类型:** `string | 'auto'`
- **默认值:** [`server.base`](/config/server/base)
- **默认值:** [server.base](/config/server/base)

[生产模式](/config/mode) 下,可以使用该选项设置静态资源的 URL 前缀,比如设置为 CDN 地址。

Expand Down
7 changes: 4 additions & 3 deletions website/docs/zh/config/server/base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- **类型:** `string`
- **默认值:** `/`
- **版本:** `>= 1.0.10`

`server.base` 用于配置服务端的[基础路径](/guide/basic/server#服务端基础路径)

Expand Down Expand Up @@ -35,12 +36,12 @@ export default {

```ts
export default {
output: {
assetPrefix: '/',
},
dev: {
assetPrefix: '/',
},
output: {
assetPrefix: 'https://cdn.example.com/assets/',
},
server: {
base: '/foo',
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/advanced/env-vars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const Image = <img src={`https://example.com/static/icon.png`} />;

你可以在 client 代码中使用 `process.env.BASE_URL` 来访问服务端的[基础路径](/guide/basic/server#服务端基础路径)

这对于我们在 html 模版中引用 [public 目录](/guide/basic/static-assets#public-目录) 资源很有帮助。
这对于我们在 HTML 模版中引用 [public 目录](/guide/basic/static-assets#public-目录) 资源很有帮助。

比如,我们通过 [server.base](/config/server/base) 配置,将服务端的基础路径设置为 `/foo`

Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/guide/basic/server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Rsbuild 配备了一个内置的开发服务器,旨在提升开发体验。当

## 服务端基础路径

默认情况下,服务端的基础路径为 `/`,用户可通过 http://localhost:3000/ 访问到 `index.html` 等产物资源及 public 目录资源
默认情况下,服务端的基础路径为 `/`,用户可通过 http://localhost:3000/ 访问到 `index.html` 等产物资源、以及 public 目录下的资源

Rsbuild 支持通过 [server.base](/config/server/base) 修改服务端的基础路径。当我们希望通过 http://localhost:3000/foo/ 访问到这些资源时,可进行如下配置
Rsbuild 支持通过 [server.base](/config/server/base) 修改服务端的基础路径。当我们希望通过 http://localhost:3000/foo/ 访问到这些资源时,可以添加如下配置

```ts title="rsbuild.config.ts"
export default {
Expand Down

0 comments on commit 3ea5da7

Please sign in to comment.