Skip to content

Commit 08b4492

Browse files
committed
feat: save vue version
1 parent 804e1ff commit 08b4492

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/import-map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function useVueImportMap(
1313
}
1414

1515
const productionMode = ref(false)
16-
const vueVersion = ref<string | undefined>()
16+
const vueVersion = ref<string | null>(null)
1717
const importMap = computed<ImportMap>(() => {
1818
const vue =
1919
(!vueVersion.value &&

src/store.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function useStore(
4242
outputMode = ref('preview'),
4343
sfcOptions = ref({}),
4444
compiler = shallowRef(defaultCompiler),
45-
vueVersion = ref(),
45+
vueVersion = ref(null),
4646

4747
locale = ref(),
4848
typescriptVersion = ref('latest'),
@@ -257,7 +257,11 @@ export function useStore(
257257
serializedState = serializedState.slice(1)
258258
const saved = JSON.parse(atou(serializedState))
259259
for (const filename in saved) {
260-
setFile(files.value, filename, saved[filename])
260+
if (filename === '_version') {
261+
vueVersion.value = saved[filename]
262+
} else {
263+
setFile(files.value, filename, saved[filename])
264+
}
261265
}
262266
}
263267
const getFiles: ReplStore['getFiles'] = () => {
@@ -266,6 +270,7 @@ export function useStore(
266270
const normalized = stripSrcPrefix(filename)
267271
exported[normalized] = file.code
268272
}
273+
if (vueVersion.value) exported._version = vueVersion.value
269274
return exported
270275
}
271276
const setFiles: ReplStore['setFiles'] = async (
@@ -385,7 +390,7 @@ export type StoreState = ToRefs<{
385390
/** `@vue/compiler-sfc` */
386391
compiler: typeof defaultCompiler
387392
/* only apply for compiler-sfc */
388-
vueVersion: string | undefined
393+
vueVersion: string | null
389394

390395
// volar-related
391396
locale: string | undefined

0 commit comments

Comments
 (0)