From 00eb42656102e1f157f4bd76f09bdaa8ba7cf474 Mon Sep 17 00:00:00 2001 From: patak <583075+patak-dev@users.noreply.github.com> Date: Tue, 10 Jun 2025 03:37:14 +0200 Subject: [PATCH 1/5] feat: add base option to import.meta.glob (#20163) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hakshu25 Co-authored-by: 翠 / green Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- guide/features.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/guide/features.md b/guide/features.md index cf1ebb70..4e26697a 100644 --- a/guide/features.md +++ b/guide/features.md @@ -580,6 +580,32 @@ const modules = import.meta.glob('./dir/*.js', { }) ``` +#### Base Path + +You can also use the `base` option to provide base path for the imports: + +```ts twoslash +import 'vite/client' +// ---cut--- +const modulesWithBase = import.meta.glob('./**/*.js', { + base: './base', +}) +``` + +```ts +// code produced by vite: +const modulesWithBase = { + './dir/foo.js': () => import('./base/dir/foo.js'), + './dir/bar.js': () => import('./base/dir/bar.js'), +} +``` + +The base option can only be a directory path relative to the importer file or absolute against the project root. Aliases and virtual modules aren't supported. + +Only the globs that are relative paths are interpreted as relative to the resolved base. + +All the resulting module keys are modified to be relative to the base if provided. + ### Glob Import Caveats Note that: From 7b96d22a4cfaafccf890bd553e7e71ee5b36057e Mon Sep 17 00:00:00 2001 From: Musanna Al Akil <43068505+Musanna-al-akil@users.noreply.github.com> Date: Tue, 10 Jun 2025 07:38:59 +0600 Subject: [PATCH 2/5] docs: update @vitejs/plugin-react-swc link in features.md (#20188) --- guide/features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/features.md b/guide/features.md index 4e26697a..1f56c612 100644 --- a/guide/features.md +++ b/guide/features.md @@ -212,7 +212,7 @@ All modern frameworks maintain integrations with Vite. Most framework plugins ar - Vue support via [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue) - Vue JSX support via [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx) - React support via [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react) -- React using SWC support via [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) +- React using SWC support via [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc) Check out the [Plugins Guide](https://vite.dev/plugins) for more information. From 7975b996e257c89bb3e2ab42d955ee20b33ce6a9 Mon Sep 17 00:00:00 2001 From: Cesar Gomez <65884507+mrcego@users.noreply.github.com> Date: Mon, 9 Jun 2025 20:41:51 -0500 Subject: [PATCH 3/5] docs: url reference for multiples environments in `this-environment-in-hooks` (#20186) --- changes/this-environment-in-hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/this-environment-in-hooks.md b/changes/this-environment-in-hooks.md index 8df7d60d..4a56ddfd 100644 --- a/changes/this-environment-in-hooks.md +++ b/changes/this-environment-in-hooks.md @@ -40,4 +40,4 @@ export function myPlugin(): Plugin { } ``` -For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name. +For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment-plugins.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name. From a2b3b512c79262b8813b861b5bfbeed0f3975044 Mon Sep 17 00:00:00 2001 From: Cesar Gomez <65884507+mrcego@users.noreply.github.com> Date: Mon, 9 Jun 2025 20:41:59 -0500 Subject: [PATCH 4/5] docs: reference for `server.moduleGraph` in `per-environments-apis migrations` (#20185) --- changes/per-environment-apis.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/per-environment-apis.md b/changes/per-environment-apis.md index 2db269e2..e59f3b63 100644 --- a/changes/per-environment-apis.md +++ b/changes/per-environment-apis.md @@ -28,6 +28,6 @@ In Vite v6, it is now possible to create any number of custom environments (`cli ## Migration Guide -- `server.moduleGraph` -> [`environment.moduleGraph`](/guide/api-environment#separate-module-graphs) +- `server.moduleGraph` -> [`environment.moduleGraph`](/guide/api-environment-instances#separate-module-graphs) - `server.transformRequest(url, ssr)` -> `environment.transformRequest(url)` - `server.warmupRequest(url, ssr)` -> `environment.warmupRequest(url)` From 2d159bb4c392811d4393bc813fb97157f75b7187 Mon Sep 17 00:00:00 2001 From: Kylin <1159469891@qq.com> Date: Wed, 11 Jun 2025 10:57:42 +0800 Subject: [PATCH 5/5] docs: update content --- changes/this-environment-in-hooks.md | 6 +----- guide/features.md | 25 +++++++------------------ 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/changes/this-environment-in-hooks.md b/changes/this-environment-in-hooks.md index ff8ad9be..6e1d8d29 100644 --- a/changes/this-environment-in-hooks.md +++ b/changes/this-environment-in-hooks.md @@ -40,8 +40,4 @@ export function myPlugin(): Plugin { } ``` -<<<<<<< HEAD -对于更稳定、长期的实现,插件钩子应该处理 [多个环境](/guide/api-environment.html#accessing-the-current-environment-in-hooks),并使用细粒度的环境选项,而不是依赖于环境的名称。 -======= -For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment-plugins.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name. ->>>>>>> a2b3b512c79262b8813b861b5bfbeed0f3975044 +对于更稳定、长期的实现,插件钩子应该处理 [多个环境](/guide/api-environment-plugins.html#accessing-the-current-environment-in-hooks),并使用细粒度的环境选项,而不是依赖于环境的名称。 diff --git a/guide/features.md b/guide/features.md index 181a8652..c3cd4945 100644 --- a/guide/features.md +++ b/guide/features.md @@ -209,17 +209,10 @@ HTML 文件位于 Vite 项目的[最前端和中心](/guide/#index-html-and-proj 所有现代框架都已和 Vite 集成。大多数框架插件由各自的框架团队维护,唯有官方的 Vue 和 React Vite 插件由 Vite 组织维护。 -<<<<<<< HEAD - Vue 支持:[@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue) - Vue JSX 支持:[@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx) - React 支持:[@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react) -- React 使用 SWC 的支持:[@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) -======= -- Vue support via [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue) -- Vue JSX support via [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx) -- React support via [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react) -- React using SWC support via [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc) ->>>>>>> a2b3b512c79262b8813b861b5bfbeed0f3975044 +- React 使用 SWC 的支持:[@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc) 查看 [插件指南](/plugins/) 了解更多信息。 @@ -587,12 +580,9 @@ const modules = import.meta.glob('./dir/*.js', { }) ``` -<<<<<<< HEAD -### Glob 导入注意事项 {#glob-import-caveats} -======= -#### Base Path +#### 基础路径 {#base-path} -You can also use the `base` option to provide base path for the imports: +你还可以使用 `base` 选项为导入提供基础路径: ```ts twoslash import 'vite/client' @@ -610,14 +600,13 @@ const modulesWithBase = { } ``` -The base option can only be a directory path relative to the importer file or absolute against the project root. Aliases and virtual modules aren't supported. +`base` 选项只能是相对于导入文件的目录路径,或者相对于项目根目录的绝对路径。不支持别名和虚拟模块。 -Only the globs that are relative paths are interpreted as relative to the resolved base. +只有相对路径的 glob 模式会被解释为相对于解析后的基础路径。 -All the resulting module keys are modified to be relative to the base if provided. +如果提供了基础路径,所有生成的模块键值都会被修改为相对于该基础路径。 -### Glob Import Caveats ->>>>>>> a2b3b512c79262b8813b861b5bfbeed0f3975044 +### Glob 导入注意事项 {#glob-import-caveats} 请注意: