|
| 1 | +From aa1ba2b67ca210fe8f03af8974b4c3c950f0cf3d Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?=E7=BF=A0?= <green@sapphi.red> |
| 3 | +Date: Thu, 12 Mar 2026 19:24:53 +0900 |
| 4 | +Subject: [PATCH] docs(apis): add document for `this.meta.viteVersion` and |
| 5 | + `*version` variables (#21824) |
| 6 | + |
| 7 | +--- |
| 8 | + docs/guide/api-javascript.md | 24 ++++++++++++++++++++++++ |
| 9 | + docs/guide/api-plugin.md | 27 +++++++++++++++++++++++++++ |
| 10 | + 2 files changed, 51 insertions(+) |
| 11 | + |
| 12 | +diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md |
| 13 | +index d12433f618aa40..0158a01638e7b4 100644 |
| 14 | +--- a/docs/guide/api-javascript.md |
| 15 | ++++ b/docs/guide/api-javascript.md |
| 16 | +@@ -461,3 +461,27 @@ Pre-processes `.css`, `.scss`, `.sass`, `.less`, `.styl` and `.stylus` files to |
| 17 | + The pre-processor used is inferred from the `filename` extension. If the `filename` ends with `.module.{ext}`, it is inferred as a [CSS module](https://github.com/css-modules/css-modules) and the returned result will include a `modules` object mapping the original class names to the transformed ones. |
| 18 | + |
| 19 | + Note that pre-processing will not resolve URLs in `url()` or `image-set()`. |
| 20 | ++ |
| 21 | ++## `version` |
| 22 | ++ |
| 23 | ++**Type:** `string` |
| 24 | ++ |
| 25 | ++The current version of Vite as a string (e.g. `"8.0.0"`). |
| 26 | ++ |
| 27 | ++## `rolldownVersion` |
| 28 | ++ |
| 29 | ++**Type:** `string` |
| 30 | ++ |
| 31 | ++The version of Rolldown used by Vite as a string (e.g. `"1.0.0"`). A re-export of [`VERSION`](https://rolldown.rs/reference/Variable.VERSION) from `rolldown`. |
| 32 | ++ |
| 33 | ++## `esbuildVersion` |
| 34 | ++ |
| 35 | ++**Type:** `string` |
| 36 | ++ |
| 37 | ++Only kept for backward compatibility. |
| 38 | ++ |
| 39 | ++## `rollupVersion` |
| 40 | ++ |
| 41 | ++**Type:** `string` |
| 42 | ++ |
| 43 | ++Only kept for backward compatibility. |
| 44 | +diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md |
| 45 | +index e418b8503c3320..c6cdbfb81fdd21 100644 |
| 46 | +--- a/docs/guide/api-plugin.md |
| 47 | ++++ b/docs/guide/api-plugin.md |
| 48 | +@@ -477,6 +477,33 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo |
| 49 | + } |
| 50 | + ``` |
| 51 | + |
| 52 | ++## Plugin Context Meta |
| 53 | ++ |
| 54 | ++For plugin hooks that has access to the plugin context, Vite exposes additional properties on `this.meta`: |
| 55 | ++ |
| 56 | ++- `this.meta.viteVersion`: The current Vite version string (e.g. `"8.0.0"`). |
| 57 | ++ |
| 58 | ++::: tip Detecting Rolldown powered Vite |
| 59 | ++ |
| 60 | ++[`this.meta.rolldownVersion`](https://rolldown.rs/reference/Interface.PluginContextMeta#rolldownversion) is only available for Rolldown powered Vite (i.e. Vite 8+). You can use it to detect whether the current Vite instance is powered by Rolldown: |
| 61 | ++ |
| 62 | ++```ts |
| 63 | ++function versionCheckPlugin(): Plugin { |
| 64 | ++ return { |
| 65 | ++ name: 'version-check', |
| 66 | ++ buildStart() { |
| 67 | ++ if (this.meta.rolldownVersion) { |
| 68 | ++ // only do something if running on a Rolldown powered Vite |
| 69 | ++ } else { |
| 70 | ++ // do something else if running on a Rollup powered Vite |
| 71 | ++ } |
| 72 | ++ }, |
| 73 | ++ } |
| 74 | ++} |
| 75 | ++``` |
| 76 | ++ |
| 77 | ++::: |
| 78 | ++ |
| 79 | + ## Output Bundle Metadata |
| 80 | + |
| 81 | + During build, Vite augments Rolldown's build output objects with a Vite-specific `viteMetadata` field. |
0 commit comments