From 5156c4f90e0922f62d25fa0c82bbefae39f4c2b6 Mon Sep 17 00:00:00 2001 From: Thiti Yamsung Date: Thu, 1 Jun 2023 21:34:02 +0700 Subject: [PATCH] fix: build fail upon have 'process.env' in *.md file. (#7257) --- .changeset/pink-ghosts-end.md | 5 +++++ packages/astro/src/vite-plugin-utils/index.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/pink-ghosts-end.md diff --git a/.changeset/pink-ghosts-end.md b/.changeset/pink-ghosts-end.md new file mode 100644 index 000000000000..7eaa13010f7a --- /dev/null +++ b/.changeset/pink-ghosts-end.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +fix: build fail upon have 'process.env' in \*.md file. diff --git a/packages/astro/src/vite-plugin-utils/index.ts b/packages/astro/src/vite-plugin-utils/index.ts index fb10de1ee934..b9cc6057649d 100644 --- a/packages/astro/src/vite-plugin-utils/index.ts +++ b/packages/astro/src/vite-plugin-utils/index.ts @@ -14,7 +14,9 @@ import { viteID } from '../core/util.js'; * in our JS representation of modules like Markdown */ export function escapeViteEnvReferences(code: string) { - return code.replace(/import\.meta\.env/g, 'import\\u002Emeta.env'); + return code + .replace(/import\.meta\.env/g, 'import\\u002Emeta.env') + .replace(/process\.env/g, 'process\\u002Eenv'); } export function getFileInfo(id: string, config: AstroConfig) {