From be07244c398a55e6e03af041c12b34c5345c46d8 Mon Sep 17 00:00:00 2001 From: ydcjeff <32727188+ydcjeff@users.noreply.github.com> Date: Thu, 3 Mar 2022 22:26:16 +0630 Subject: [PATCH 1/4] docs: vite only replace __dirname, __filename, import.meta.url in cjs --- docs/config/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 27234b01a9b4af..43eb6ef1f529f8 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -27,7 +27,9 @@ You can also explicitly specify a config file to use with the `--config` CLI opt vite --config my-config.js ``` -Note that Vite will replace `__filename`, `__dirname`, and `import.meta.url`. Using these as variable names will result in an error: +::: tip NOTE +Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS context**. Using these as variable names will result in an error: +::: ```js const __filename = "value" From a47ac0187202ccfe0234a4871f5289071139af4c Mon Sep 17 00:00:00 2001 From: ydcjeff <32727188+ydcjeff@users.noreply.github.com> Date: Sat, 5 Mar 2022 15:07:06 +0630 Subject: [PATCH 2/4] docs: config replacement happen on TS config file --- docs/config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 43eb6ef1f529f8..3dfe55d2b471de 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -28,7 +28,7 @@ vite --config my-config.js ``` ::: tip NOTE -Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS context**. Using these as variable names will result in an error: +Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS context** and **TS config file** (whether there is `type: "module"` or not). Using these as variable names will result in an error: ::: ```js From 3c6a7632567be5b9547966d5937a445d5ea93173 Mon Sep 17 00:00:00 2001 From: ydcjeff <32727188+ydcjeff@users.noreply.github.com> Date: Sat, 5 Mar 2022 19:53:12 +0630 Subject: [PATCH 3/4] chore: apply suggestions from code review --- docs/config/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 3dfe55d2b471de..136bb7ed3e14e9 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -28,8 +28,7 @@ vite --config my-config.js ``` ::: tip NOTE -Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS context** and **TS config file** (whether there is `type: "module"` or not). Using these as variable names will result in an error: -::: +Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS** and **TypeScript** config files. Using these as variable names will result in an error: ```js const __filename = "value" @@ -37,6 +36,8 @@ const __filename = "value" const "path/vite.config.js" = "value" ``` +::: + ### Config Intellisense Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints: From 4e55247f3a164902565efd6c2bf16c2008ad2115 Mon Sep 17 00:00:00 2001 From: Jeff Yang <32727188+ydcjeff@users.noreply.github.com> Date: Sat, 19 Mar 2022 12:19:33 +0630 Subject: [PATCH 4/4] Update docs/config/index.md Co-authored-by: Bjorn Lu --- docs/config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 136bb7ed3e14e9..3a8f2e3d03422f 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -28,7 +28,7 @@ vite --config my-config.js ``` ::: tip NOTE -Vite will only replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS** and **TypeScript** config files. Using these as variable names will result in an error: +Vite will replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS** and **TypeScript** config files. Using these as variable names will result in an error: ```js const __filename = "value"