Skip to content

Commit 1351692

Browse files
committed
docs: update descriptions about cjs and esm
1 parent 2c2d8f3 commit 1351692

File tree

7 files changed

+7
-59
lines changed

7 files changed

+7
-59
lines changed

docs/advanced/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ The above figure shows a brief overview of the VuePress architecture:
1111

1212
As a developer, you must be aware of that VuePress has two main parts: **Node App** and **Client App**, which is important when developing plugins and themes:
1313

14-
- The entry file of a plugin or a theme will be loaded in Node App. So you need to use CommonJS format for them.
15-
- Client files will be loaded in Client App, which will be handled by bundler. For example, layouts, components, app setup files, app enhance files, etc. You'd better use ESM format for them.
14+
- The entry file of a plugin or a theme will be loaded in Node App.
15+
- Client files will be loaded in Client App, which will be handled by bundler. For example, layouts, components, app setup files, app enhance files, etc.
1616

1717
## Core Process and Hooks
1818

docs/advanced/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const fooPlugin = {
1515
}
1616
```
1717

18-
A plugin could also be a function that receives the [app instace](../reference/node-api.md#app) as the param and returns a *Plugin Object*, which is called a *Plugin Function*:
18+
A plugin could also be a function that receives the [app instance](../reference/node-api.md#app) as the param and returns a *Plugin Object*, which is called a *Plugin Function*:
1919

2020
```ts
2121
const barPlugin = (app) => {

docs/guide/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Similarly, we also have a convention for client config file paths (in order of p
7373
- `.vuepress/client.js`
7474
- `.vuepress/client.mjs`
7575

76-
Notice that the client config file should be in ESM format:
76+
A basic client config file looks like this:
7777

7878
```ts
7979
import { defineClientConfig } from '@vuepress/client'

docs/reference/bundler/vite.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,3 @@ export default defineUserConfig({
4141

4242
- Also see:
4343
- [Vite > Plugins > Official Plugins](https://vitejs.dev/plugins/#vitejs-plugin-vue)
44-
45-
## FAQ
46-
47-
### SSR Externals Issue
48-
49-
When you are importing a third-party library (called `foo-lib`), a common error your might meet in build is:
50-
51-
```sh
52-
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/foo-lib
53-
```
54-
55-
To get rid of it, you need to set `ssr.noExternal` option:
56-
57-
```ts
58-
export default defineUserConfig({
59-
bundler: viteBundler({
60-
viteOptions: {
61-
ssr: {
62-
noExternal: ['foo-lib'],
63-
},
64-
},
65-
}),
66-
})
67-
```
68-
69-
VuePress is using Vite server-side rendering (SSR) to pre-render markdown to HTML files. Although it's quite usable and work well with VuePress, it's still marked as experimental and might have some issues. To fully understand what the above error is, reading [Vite SSR Externals Guide](https://vitejs.dev/guide/ssr.html#ssr-externals) would be helpful.

docs/zh/advanced/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
作为开发者,你必须要意识到 VuePress 分为两个主要部分: **Node App****Client App** ,这一点对于开发插件和主题来说都十分重要。
1313

14-
- 插件或者主题的入口文件会在 Node App 中被加载,因此它们需要使用 CommonJS 格式
15-
- 客户端文件会在 Client App 中被加载,也就是会被 Bundler 处理。比如布局、组件、App Setup 文件、App Enhance 文件等。它们最好使用 ESM 格式。
14+
- 插件或者主题的入口文件会在 Node App 中被加载。
15+
- 客户端文件会在 Client App 中被加载,也就是会被 Bundler 处理。比如布局、组件、App Setup 文件、App Enhance 文件等。
1616

1717
## 核心流程与 Hooks
1818

docs/zh/guide/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default defineUserConfig({
7676
- `.vuepress/client.js`
7777
- `.vuepress/client.mjs`
7878

79-
需要注意的是,客户端配置文件需要使用 ESM 格式
79+
一个基础的客户端配置文件是这样的
8080

8181
```ts
8282
import { defineClientConfig } from '@vuepress/client'

docs/zh/reference/bundler/vite.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,3 @@ export default defineUserConfig({
4141

4242
- 参考:
4343
- [Vite > 插件 > 官方插件](https://cn.vitejs.dev/plugins/#vitejsplugin-vue)
44-
45-
## 常见问题
46-
47-
### SSR Externals 问题
48-
49-
当你引入一个第三方库(如 `foo-lib`)时,你可能会在构建时遇到一个常见的错误:
50-
51-
```sh
52-
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/foo-lib
53-
```
54-
55-
此时,你需要设置 `ssr.noExternal` 配置项来解决它:
56-
57-
```ts
58-
export default defineUserConfig({
59-
bundler: viteBundler({
60-
viteOptions: {
61-
ssr: {
62-
noExternal: ['foo-lib'],
63-
},
64-
},
65-
}),
66-
})
67-
```
68-
69-
VuePress 使用 Vite 服务端渲染 (SSR) 来将 Markdown 预渲染成 HTML 文件。尽管它可以在 VuePress 中正常使用,但该功能仍然被标记为实验性能力,因此可能会有一些小问题。想要完全理解上面的报错原因,你可以去了解一下 [Vite SSR Externals 文档](https://cn.vitejs.dev/guide/ssr.html#ssr-externals)

0 commit comments

Comments
 (0)