From f90f2deaea91164cb82a33c6b062c41cbde88235 Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Tue, 31 Jan 2023 22:08:36 -0800 Subject: [PATCH 1/7] docs: fix generated output code for custom queries (#11869) --- guide/features.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/guide/features.md b/guide/features.md index c84e9965..9ef89d3f 100644 --- a/guide/features.md +++ b/guide/features.md @@ -443,10 +443,8 @@ const modules = import.meta.glob('./dir/*.js', { ```ts // code produced by vite: const modules = { - './dir/foo.js': () => - import('./dir/foo.js?foo=bar&bar=true').then((m) => m.setup), - './dir/bar.js': () => - import('./dir/bar.js?foo=bar&bar=true').then((m) => m.setup), + './dir/foo.js': () => import('./dir/foo.js?foo=bar&bar=true'), + './dir/bar.js': () => import('./dir/bar.js?foo=bar&bar=true'), } ``` From dca3fa750626620880e5ffb962aef551c201d29e Mon Sep 17 00:00:00 2001 From: Ben Briggs Date: Wed, 1 Feb 2023 03:47:02 -0500 Subject: [PATCH 2/7] docs: distinguish plugins config used for workers in build and serve (#11834) --- config/worker-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/worker-options.md b/config/worker-options.md index c7a5e189..840caa60 100644 --- a/config/worker-options.md +++ b/config/worker-options.md @@ -13,7 +13,7 @@ Output format for worker bundle. - **Type:** [`(Plugin | Plugin[])[]`](./shared-options#plugins) -Vite plugins that apply to worker bundle. Note that [config.plugins](./shared-options#plugins) does not apply to workers, it should be configured here instead. +Vite plugins that apply to worker bundle. Note that [config.plugins](./shared-options#plugins) only applies to workers in dev, it should be configured here instead for build. ## worker.rollupOptions From 3b72b13e24b4fec88701564993578d431545f2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 1 Feb 2023 18:52:45 +0900 Subject: [PATCH 3/7] docs: add troubleshooting for browser compat (#11877) Co-authored-by: Bjorn Lu --- guide/troubleshooting.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guide/troubleshooting.md b/guide/troubleshooting.md index 3af4cfa5..89827059 100644 --- a/guide/troubleshooting.md +++ b/guide/troubleshooting.md @@ -121,6 +121,16 @@ You will need to access the file with `http` protocol. The easiest way to achiev ## Others +### Module externalized for browser compatibility + +When you use a Node.js module in the browser, Vite will output the following warning. + +> Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code. + +This is because Vite does not automatically polyfill Node.js modules. + +We recommend avoiding Node.js modules for browser code to reduce the bundle size, although you can add polyfills manually. If the module is imported from a third-party library (that's meant to be used in the browser), it's advised to report the issue to the respective library. + ### Syntax Error / Type Error happens Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This is because Vite uses ESM and it is always [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) inside ESM. From c66e24907726317e7e4b850ab17217c3d879e516 Mon Sep 17 00:00:00 2001 From: Ryan Patterson Date: Wed, 1 Feb 2023 02:01:16 -0800 Subject: [PATCH 4/7] docs: add documentation about import.meta.hot magic (#11684) --- guide/api-hmr.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guide/api-hmr.md b/guide/api-hmr.md index ee66f73b..9af51e8e 100644 --- a/guide/api-hmr.md +++ b/guide/api-hmr.md @@ -70,9 +70,9 @@ if (import.meta.hot) { A module that "accepts" hot updates is considered an **HMR boundary**. -Note that Vite's HMR does not actually swap the originally imported module: if an HMR boundary module re-exports imports from a dep, then it is responsible for updating those re-exports (and these exports must be using `let`). In addition, importers up the chain from the boundary module will not be notified of the change. +Vite's HMR does not actually swap the originally imported module: if an HMR boundary module re-exports imports from a dep, then it is responsible for updating those re-exports (and these exports must be using `let`). In addition, importers up the chain from the boundary module will not be notified of the change. This simplified HMR implementation is sufficient for most dev use cases, while allowing us to skip the expensive work of generating proxy modules. -This simplified HMR implementation is sufficient for most dev use cases, while allowing us to skip the expensive work of generating proxy modules. +Vite requires that the call to this function appears as `import.meta.hot.accept(` (whitespace-sensitive) in the source code in order for the module to accept update. This is a requirement of the static analysis that Vite does to enable HMR support for a module. ## `hot.accept(deps, cb)` From 3bc9236de0e1b438567a856a421fa7ad312565d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 1 Feb 2023 21:41:34 +0900 Subject: [PATCH 5/7] docs: remove wrong vite command description (#11879) --- guide/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/cli.md b/guide/cli.md index 3cf67921..15bac44b 100644 --- a/guide/cli.md +++ b/guide/cli.md @@ -4,7 +4,7 @@ ### `vite` -Start Vite dev server in the current directory. Will enter the watch mode in development environment and run mode in CI automatically. +Start Vite dev server in the current directory. #### Usage From d550a23a31b393f9fad0d2a4053adc1c65d4cc51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 1 Feb 2023 21:42:51 +0900 Subject: [PATCH 6/7] docs: tweak wording (#11876) --- config/index.md | 2 +- config/shared-options.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/index.md b/config/index.md index 56fbd4be..f5d479ad 100644 --- a/config/index.md +++ b/config/index.md @@ -82,7 +82,7 @@ export default defineConfig(async ({ command, mode }) => { }) ``` -## Environment Variables +## Using Environment Variables in Config Environmental Variables can be obtained from `process.env` as usual. diff --git a/config/shared-options.md b/config/shared-options.md index 167850cd..e72841d8 100644 --- a/config/shared-options.md +++ b/config/shared-options.md @@ -37,7 +37,7 @@ See [Env Variables and Modes](/guide/env-and-mode) for more details. Define global constant replacements. Entries will be defined as globals during dev and statically replaced during build. -- Starting from `2.0.0-beta.70`, string values will be used as raw expressions, so if defining a string constant, it needs to be explicitly quoted (e.g. with `JSON.stringify`). +- String values will be used as raw expressions, so if defining a string constant, **it needs to be explicitly quoted** (e.g. with `JSON.stringify`). - To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier. From cb6f018e14dcabe1179ba4bb648a3826adf298ac Mon Sep 17 00:00:00 2001 From: ShenQingchuan Date: Sat, 4 Feb 2023 11:44:37 +0800 Subject: [PATCH 7/7] docs(cn): resolve all conflicts --- config/index.md | 6 +----- config/shared-options.md | 6 +----- config/worker-options.md | 6 +----- guide/api-hmr.md | 10 ++-------- guide/cli.md | 6 +----- guide/features.md | 7 ------- guide/troubleshooting.md | 14 +++++--------- 7 files changed, 11 insertions(+), 44 deletions(-) diff --git a/config/index.md b/config/index.md index faacd05f..c82d7a37 100644 --- a/config/index.md +++ b/config/index.md @@ -78,11 +78,7 @@ export default defineConfig(async ({ command, mode }) => { }) ``` -<<<<<<< HEAD -## 环境变量 {#environment-variables} -======= -## Using Environment Variables in Config ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +## 在配置中使用环境变量 {#using-environment-variables-in-config} 环境变量通常可以从 `process.env` 获得。 diff --git a/config/shared-options.md b/config/shared-options.md index 498eea05..b04d2f45 100644 --- a/config/shared-options.md +++ b/config/shared-options.md @@ -37,11 +37,7 @@ 定义全局常量替换方式。其中每项在开发环境下会被定义在全局,而在构建时被静态替换。 -<<<<<<< HEAD -- 从 `2.0.0-beta.70` 开始,string 值会以原始表达式形式使用,所以如果定义了一个字符串常量,它需要被显式地打引号。(例如使用 `JSON.stringify`) -======= -- String values will be used as raw expressions, so if defining a string constant, **it needs to be explicitly quoted** (e.g. with `JSON.stringify`). ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +- String 值会以原始表达式形式使用,所以如果定义了一个字符串常量,**它需要被显式地打引号。**(例如使用 `JSON.stringify`) - 为了与 [esbuild 的行为](https://esbuild.github.io/api/#define)保持一致,表达式必须为一个 JSON 对象(null、boolean、number、string、数组或对象),亦或是一个单独的标识符。 diff --git a/config/worker-options.md b/config/worker-options.md index b895abeb..2d653f32 100644 --- a/config/worker-options.md +++ b/config/worker-options.md @@ -13,11 +13,7 @@ worker 打包时的输出类型。 - **类型:** [`(Plugin | Plugin[])[]`](./shared-options#plugins) -<<<<<<< HEAD -应用于 worker 打包的 Vite 插件。注意 [config.plugins](./shared-options#plugins) 不会应用于 worker,而是应该在这里配置所用到的插件。 -======= -Vite plugins that apply to worker bundle. Note that [config.plugins](./shared-options#plugins) only applies to workers in dev, it should be configured here instead for build. ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +应用于 worker 打包的 Vite 插件。注意 [config.plugins](./shared-options#plugins) 仅会在开发(dev)阶段应用于 worker,若要配置在构建(build)阶段应用于 worker 的插件则应该在本选项这里配置。 ## worker.rollupOptions diff --git a/guide/api-hmr.md b/guide/api-hmr.md index a136f7ba..c7aad702 100644 --- a/guide/api-hmr.md +++ b/guide/api-hmr.md @@ -70,15 +70,9 @@ if (import.meta.hot) { “接受” 热更新的模块被认为是 **HMR 边界**。 -<<<<<<< HEAD -请注意,Vite 的 HMR 实际上并不替换最初导入的模块:如果 HMR 边界模块从某个依赖重新导出其导入,则它应负责更新这些重新导出的模块(这些导出必须使用 `let`)。此外,从边界模块向上的导入者将不会收到更新。 +Vite 的 HMR 实际上并不替换最初导入的模块:如果 HMR 边界模块从某个依赖重新导出其导入,则它应负责更新这些重新导出的模块(这些导出必须使用 `let`)。此外,从边界模块向上的导入者将不会收到更新。这种简化的 HMR 实现对于大多数开发用例来说已经足够了,同时允许我们跳过生成代理模块的昂贵工作。 -这种简化的 HMR 实现对于大多数开发用例来说已经足够了,同时允许我们跳过生成代理模块的昂贵工作。 -======= -Vite's HMR does not actually swap the originally imported module: if an HMR boundary module re-exports imports from a dep, then it is responsible for updating those re-exports (and these exports must be using `let`). In addition, importers up the chain from the boundary module will not be notified of the change. This simplified HMR implementation is sufficient for most dev use cases, while allowing us to skip the expensive work of generating proxy modules. - -Vite requires that the call to this function appears as `import.meta.hot.accept(` (whitespace-sensitive) in the source code in order for the module to accept update. This is a requirement of the static analysis that Vite does to enable HMR support for a module. ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +Vite 要求这个函数的调用在源代码中显示为 `import.meta.hot.accept(`(对空格敏感),这样模块才能接受更新。这是 Vite 为使模块支持 HMR 而进行的静态分析的一个要求。 ## `hot.accept(deps, cb)` {#hot-accept-deps-cb} diff --git a/guide/cli.md b/guide/cli.md index 39ec9dd7..128016c1 100644 --- a/guide/cli.md +++ b/guide/cli.md @@ -4,11 +4,7 @@ ### `vite` {#vite} -<<<<<<< HEAD -在当前目录下启动 Vite 开发服务器,将自动进入开发环境的观察模式和 CI 的运行模式。 -======= -Start Vite dev server in the current directory. ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +在当前目录下启动 Vite 开发服务器。 #### 使用 {#usage} diff --git a/guide/features.md b/guide/features.md index 95312d9b..754c79a4 100644 --- a/guide/features.md +++ b/guide/features.md @@ -443,15 +443,8 @@ const modules = import.meta.glob('./dir/*.js', { ```ts // vite 生成的代码 const modules = { -<<<<<<< HEAD - './dir/foo.js': () => - import('./dir/foo.js?foo=bar&bar=true'), - './dir/bar.js': () => - import('./dir/bar.js?foo=bar&bar=true'), -======= './dir/foo.js': () => import('./dir/foo.js?foo=bar&bar=true'), './dir/bar.js': () => import('./dir/bar.js?foo=bar&bar=true'), ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 } ``` diff --git a/guide/troubleshooting.md b/guide/troubleshooting.md index f5fe663c..ead37afe 100644 --- a/guide/troubleshooting.md +++ b/guide/troubleshooting.md @@ -121,21 +121,17 @@ This can be caused by a circular dependency. To solve this, try breaking the loo ## 其他 {#others} -<<<<<<< HEAD -### Syntax Error / Type Error {#syntax-error-type-error-happens} -======= -### Module externalized for browser compatibility +### Module externalized for browser compatibility {#module-externalized-for-browser-compatibility} -When you use a Node.js module in the browser, Vite will output the following warning. +当你在浏览器中使用一个 Node.js 模块时,Vite 会输出以下警告: > Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code. -This is because Vite does not automatically polyfill Node.js modules. +这是因为 Vite 不会自动 polyfill Node.js 的内建模块。 -We recommend avoiding Node.js modules for browser code to reduce the bundle size, although you can add polyfills manually. If the module is imported from a third-party library (that's meant to be used in the browser), it's advised to report the issue to the respective library. +我们推荐你不要再浏览器中使用 Node.js 模块以减小包体积,尽管你可以为其手动添加 polyfill。如果该模块是被某个第三方库(这里意为某个在浏览器中使用的库)导入的,则建议向对应库提交一个 issue。 -### Syntax Error / Type Error happens ->>>>>>> d550a23a31b393f9fad0d2a4053adc1c65d4cc51 +### Syntax Error / Type Error {#syntax-error-type-error-happens} Vite 无法处理、也不支持仅可在非严格模式(sloppy mode)下运行的代码。这是因为 Vite 使用了 ESM 并且始终在 ESM 中使用 [严格模式](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)。