From c74673fb55d2232de55562e62a818142681bdc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 14 Feb 2024 10:42:16 +0800 Subject: [PATCH] fix: add vue import maps for default import map --- src/import-map.ts | 3 ++- src/store.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/import-map.ts b/src/import-map.ts index 62a27d6d..bc11cd50 100644 --- a/src/import-map.ts +++ b/src/import-map.ts @@ -5,6 +5,7 @@ export function useVueImportMap( runtimeDev?: string | (() => string) runtimeProd?: string | (() => string) serverRenderer?: string | (() => string) + vueVersion?: string | null } = {}, ) { function normalizeDefaults(defaults?: string | (() => string)) { @@ -13,7 +14,7 @@ export function useVueImportMap( } const productionMode = ref(false) - const vueVersion = ref(null) + const vueVersion = ref(defaults.vueVersion || null) const importMap = computed(() => { const vue = (!vueVersion.value && diff --git a/src/store.ts b/src/store.ts index 556c7717..195c2ccf 100644 --- a/src/store.ts +++ b/src/store.ts @@ -18,7 +18,7 @@ import type { } from 'vue/compiler-sfc' import type { OutputModes } from './types' import type { editor } from 'monaco-editor-core' -import { type ImportMap, mergeImportMap } from './import-map' +import { type ImportMap, mergeImportMap, useVueImportMap } from './import-map' import welcomeSFCCode from './template/welcome.vue?raw' import newSFCCode from './template/new-sfc.vue?raw' @@ -35,7 +35,7 @@ export function useStore( welcomeSFC: welcomeSFCCode, newSFC: newSFCCode, }), - builtinImportMap = ref({}), + builtinImportMap = undefined!, // set later errors = ref([]), showOutput = ref(false), @@ -51,6 +51,11 @@ export function useStore( }: Partial = {}, serializedState?: string, ): ReplStore { + if (!builtinImportMap) { + ;({ importMap: builtinImportMap, vueVersion } = useVueImportMap({ + vueVersion: vueVersion.value, + })) + } const loading = ref(false) function applyBuiltinImportMap() {