diff --git a/packages/sfc-playground/package.json b/packages/sfc-playground/package.json index c0cd7e10c..867333e1a 100644 --- a/packages/sfc-playground/package.json +++ b/packages/sfc-playground/package.json @@ -13,7 +13,7 @@ "vite": "^5.0.5" }, "dependencies": { - "@vue/repl": "4.0.0-alpha.0", + "@vue/repl": "4.0.0-alpha.1", "file-saver": "^2.0.5", "jszip": "^3.10.1", "vue": "workspace:*" diff --git a/packages/sfc-playground/src/App.vue b/packages/sfc-playground/src/App.vue index c01f05680..e681cf374 100644 --- a/packages/sfc-playground/src/App.vue +++ b/packages/sfc-playground/src/App.vue @@ -8,10 +8,12 @@ import { mergeImportMap, File, StoreState, + ImportMap, } from '@vue/repl' import type Monaco from '@vue/repl/monaco-editor' import type CodeMirror from '@vue/repl/codemirror-editor' import { ref, watchEffect, onMounted, computed, shallowRef, watch } from 'vue' +import welcomeSFC from './welcome.vue?raw' const EditorComponent = shallowRef() @@ -52,15 +54,20 @@ const { : `${location.origin}/src/vue-server-renderer-dev-proxy`, }) -const importMap = computed(() => - mergeImportMap(vueImportMap.value, { +const importMap = computed(() => { + const vapor = import.meta.env.PROD + ? `${location.origin}/vue-vapor.esm-browser.js` + : `${location.origin}/src/vue-vapor-dev-proxy` + + const vaporImportMap: ImportMap = { imports: { - 'vue/vapor': import.meta.env.PROD - ? `${location.origin}/vue-vapor.esm-browser.js` - : `${location.origin}/src/vue-vapor-dev-proxy`, + 'vue/vapor': vapor, }, - }), -) + } + if (useVaporMode.value) vaporImportMap.imports!.vue = vapor + + return mergeImportMap(vueImportMap.value, vaporImportMap) +}) let hash = location.hash.slice(1) if (hash.startsWith('__DEV__')) { @@ -81,7 +88,6 @@ if (hash.startsWith('__VAPOR__')) { } const files: StoreState['files'] = ref(Object.create(null)) -const mainFile = ref('src/App.vue') // enable experimental features const sfcOptions = computed( @@ -110,7 +116,9 @@ const store = useStore( vueVersion, builtinImportMap: importMap, sfcOptions, - mainFile, + template: ref({ + welcomeSFC: welcomeSFC, + }), }, hash, ) @@ -132,11 +140,13 @@ watch( `
`, true, ) - mainFile.value = 'src/index.html' - store.activeFile = files.value['src/App.vue'] + store.mainFile = 'src/index.html' } else if (files.value['src/index.html']?.hidden) { delete files.value['src/index.html'] - mainFile.value = 'src/App.vue' + store.mainFile = 'src/App.vue' + if (store.activeFile.filename === 'src/index.html') { + store.activeFile = files.value['src/App.vue'] + } } }, { immediate: true }, diff --git a/packages/sfc-playground/src/welcome.vue b/packages/sfc-playground/src/welcome.vue new file mode 100644 index 000000000..48b3c9d0e --- /dev/null +++ b/packages/sfc-playground/src/welcome.vue @@ -0,0 +1,12 @@ + + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75dd6ed38..c7b9fdd9f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -371,8 +371,8 @@ importers: packages/sfc-playground: dependencies: '@vue/repl': - specifier: 4.0.0-alpha.0 - version: 4.0.0-alpha.0 + specifier: 4.0.0-alpha.1 + version: 4.0.0-alpha.1 file-saver: specifier: ^2.0.5 version: 2.0.5 @@ -1637,8 +1637,8 @@ packages: engines: {node: '>= 0.12.0'} dev: true - /@vue/repl@4.0.0-alpha.0: - resolution: {integrity: sha512-kGgnon2yV1y0eKeWatys4by32XXCDSdq31Rwx0cd8xXAIK0GIL0AeSMCvVUrNE2ke8rFVYe6xMmpOd1iCcM0Zg==} + /@vue/repl@4.0.0-alpha.1: + resolution: {integrity: sha512-BK9D7AgpYAWVrtd7Kkc3CotU/ox8l+mPjsLgK16ZP+Ldj8jXPrJtzYQ2rTQNRJOxVSVx5acftDTLDLENFhQdDw==} dev: false /@zeit/schemas@2.29.0: