diff --git a/docs/config/index.md b/docs/config/index.md index 27234b01a9b4af..4d42063e30e82c 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -139,9 +139,11 @@ export default defineConfig(async ({ command, mode }) => { - Replacements are performed only when the match is surrounded by word boundaries (`\b`). + ::: warning Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only. For example, `process.env.FOO` and `__APP_VERSION__` are good fits. But `process` or `global` should not be put into this option. Variables can be shimmed or polyfilled instead. + ::: ::: tip NOTE For TypeScript users, make sure to add the type declarations in the `env.d.ts` or `vite-env.d.ts` file to get type checks and Intellisense. diff --git a/packages/playground/define/__tests__/define.spec.ts b/packages/playground/define/__tests__/define.spec.ts index f417026ebd186d..f5eb78ea4e2766 100644 --- a/packages/playground/define/__tests__/define.spec.ts +++ b/packages/playground/define/__tests__/define.spec.ts @@ -20,13 +20,4 @@ test('string', async () => { expect(await page.textContent('.spread-array')).toBe( JSON.stringify([...defines.__STRING__]) ) - expect(await page.textContent('.import-file')).not.toBe( - `import * from "${defines.__IMPORT_FILE_NAME__}"` - ) - expect(await page.textContent('.export-file')).not.toBe( - `export * from "${defines.__EXPORT_FILE_NAME__}"` - ) - expect(await page.textContent('.path')).not.toBe( - `import * from "xxxx/${defines.PATH}"` - ) }) diff --git a/packages/playground/define/index.html b/packages/playground/define/index.html index a285764dd9e0b4..bf6a9c59689396 100644 --- a/packages/playground/define/index.html +++ b/packages/playground/define/index.html @@ -9,9 +9,6 @@

Define

process as property:

spread object:

spread array:

-

import file:

-

export file:

-

path: