From 37ce32b107864332eeebbc406a817d78ae8d982a Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 6 Apr 2023 18:08:23 +0800 Subject: [PATCH] fix: avoid including vue in import map if using default URLs --- src/store.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/store.ts b/src/store.ts index 27f44052..9d8438df 100644 --- a/src/store.ts +++ b/src/store.ts @@ -168,7 +168,23 @@ export class ReplStore implements Store { } serialize() { - return '#' + utoa(JSON.stringify(this.getFiles())) + const files = this.getFiles() + const importMap = files['import-map.json'] + if (importMap) { + const { imports } = JSON.parse(importMap) + if (imports['vue'] === this.defaultVueRuntimeURL) { + delete imports['vue'] + } + if (imports['vue/server-renderer'] === this.defaultVueServerRendererURL) { + delete imports['vue/server-renderer'] + } + if (!Object.keys(imports).length) { + delete files['import-map.json'] + } else { + files['import-map.json'] = JSON.stringify({ imports }, null, 2) + } + } + return '#' + utoa(JSON.stringify(files)) } getFiles() { @@ -209,7 +225,8 @@ export class ReplStore implements Store { JSON.stringify( { imports: { - vue: this.defaultVueRuntimeURL + vue: this.defaultVueRuntimeURL, + 'vue/server-renderer': this.defaultVueServerRendererURL } }, null,