From 1a16f123e0781449c511af2d0112b8c4639972f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 30 May 2022 03:23:12 +0900 Subject: [PATCH] fix(plugin-legacy): empty base makes import fail (fixes #4212) (#8387) --- packages/plugin-legacy/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 3a9fb253d4658a..bc21d4d917d8df 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -419,6 +419,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { chunk.facadeModuleId ) if (legacyEntryFilename) { + // `assets/foo.js` means importing "named register" in SystemJS + const nonBareBase = config.base === '' ? './' : config.base tags.push({ tag: 'script', attrs: { @@ -427,7 +429,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // script content will stay consistent - which allows using a constant // hash value for CSP. id: legacyEntryId, - 'data-src': config.base + legacyEntryFilename + 'data-src': nonBareBase + legacyEntryFilename }, children: systemJSInlineCode, injectTo: 'body'