Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changes/per-environment-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ future: {

## 迁移指南 {#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)`
2 changes: 1 addition & 1 deletion changes/this-environment-in-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export function myPlugin(): Plugin {
}
```

对于更稳定、长期的实现,插件钩子应该处理 [多个环境](/guide/api-environment.html#accessing-the-current-environment-in-hooks),并使用细粒度的环境选项,而不是依赖于环境的名称。
对于更稳定、长期的实现,插件钩子应该处理 [多个环境](/guide/api-environment-plugins.html#accessing-the-current-environment-in-hooks),并使用细粒度的环境选项,而不是依赖于环境的名称。
28 changes: 27 additions & 1 deletion guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ HTML 文件位于 Vite 项目的[最前端和中心](/guide/#index-html-and-proj
- 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)
- React 使用 SWC 的支持:[@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc)

查看 [插件指南](/plugins/) 了解更多信息。

Expand Down Expand Up @@ -580,6 +580,32 @@ const modules = import.meta.glob('./dir/*.js', {
})
```

#### 基础路径 {#base-path}

你还可以使用 `base` 选项为导入提供基础路径:

```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'),
}
```

`base` 选项只能是相对于导入文件的目录路径,或者相对于项目根目录的绝对路径。不支持别名和虚拟模块。

只有相对路径的 glob 模式会被解释为相对于解析后的基础路径。

如果提供了基础路径,所有生成的模块键值都会被修改为相对于该基础路径。

### Glob 导入注意事项 {#glob-import-caveats}

请注意:
Expand Down