From 416f190aa92f06a06f3ded403fb1e4cb8729256d Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 11 Feb 2021 17:00:51 -0500 Subject: [PATCH] feat(plugin-legacy): inject import.meta.env.LEGACY --- .../legacy/__tests__/legacy.spec.ts | 6 ++ packages/playground/legacy/index.html | 1 + packages/playground/legacy/main.js | 4 + packages/playground/legacy/package.json | 3 +- packages/plugin-legacy/README.md | 2 + packages/plugin-legacy/index.js | 75 ++++++++++++++++++- packages/plugin-legacy/package.json | 1 + 7 files changed, 88 insertions(+), 4 deletions(-) diff --git a/packages/playground/legacy/__tests__/legacy.spec.ts b/packages/playground/legacy/__tests__/legacy.spec.ts index 5ac67eb368105e..aff02741711964 100644 --- a/packages/playground/legacy/__tests__/legacy.spec.ts +++ b/packages/playground/legacy/__tests__/legacy.spec.ts @@ -1,3 +1,9 @@ +import { isBuild } from '../../testUtils' + test('should work', async () => { expect(await page.textContent('#app')).toMatch('Hello') }) + +test('import.meta.env.LEGACY', async () => { + expect(await page.textContent('#env')).toMatch(isBuild ? 'true' : 'false') +}) diff --git a/packages/playground/legacy/index.html b/packages/playground/legacy/index.html index 26cb9f4685e81d..aef4bccfc61f74 100644 --- a/packages/playground/legacy/index.html +++ b/packages/playground/legacy/index.html @@ -1,2 +1,3 @@

+
diff --git a/packages/playground/legacy/main.js b/packages/playground/legacy/main.js index 973cd65966ad09..84409b57793631 100644 --- a/packages/playground/legacy/main.js +++ b/packages/playground/legacy/main.js @@ -4,3 +4,7 @@ async function run() { } run() + +document.getElementById('env').textContent = `is legacy: ${ + import.meta.env.LEGACY +}` diff --git a/packages/playground/legacy/package.json b/packages/playground/legacy/package.json index 9c7c676b3d186e..89a5130f8e9eb9 100644 --- a/packages/playground/legacy/package.json +++ b/packages/playground/legacy/package.json @@ -10,6 +10,5 @@ }, "devDependencies": { "@vitejs/plugin-legacy": "^1.0.0" - }, - "dependencies": {} + } } diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md index 259550b48fb404..cc38130d184691 100644 --- a/packages/plugin-legacy/README.md +++ b/packages/plugin-legacy/README.md @@ -12,6 +12,8 @@ By default, this plugin will: - Inject `