From 6bc45a24e2d1c75ec0940a38c0421f4bb4003450 Mon Sep 17 00:00:00 2001
From: Bjorn Lu
Date: Sun, 13 Mar 2022 23:39:32 +0800
Subject: [PATCH] fix(asset): allow non-existent url (#7306)
---
packages/playground/assets/__tests__/assets.spec.ts | 6 ++++++
packages/playground/assets/index.html | 8 ++++++++
packages/vite/src/node/plugins/asset.ts | 4 ++--
packages/vite/src/node/plugins/assetImportMetaUrl.ts | 9 ++++++++-
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts
index 191da897858dd5..f65e3009a7aa71 100644
--- a/packages/playground/assets/__tests__/assets.spec.ts
+++ b/packages/playground/assets/__tests__/assets.spec.ts
@@ -232,6 +232,12 @@ test('new URL(`${dynamic}`, import.meta.url)', async () => {
)
})
+test('new URL(`non-existent`, import.meta.url)', async () => {
+ expect(await page.textContent('.non-existent-import-meta-url')).toMatch(
+ '/foo/non-existent'
+ )
+})
+
if (isBuild) {
test('manifest', async () => {
const manifest = readManifest('foo')
diff --git a/packages/playground/assets/index.html b/packages/playground/assets/index.html
index e33e9a7cdaaf7d..25c889a445b771 100644
--- a/packages/playground/assets/index.html
+++ b/packages/playground/assets/index.html
@@ -166,6 +166,11 @@ new URL(`./${dynamic}`, import.meta.url,) (with comma)
+new URL(`non-existent`, import.meta.url)
+
+
+
+
simple script tag import-expression