For advanced customization, you can manually initialize the REPL state by using useStore and useVueImportMap. This allows you to control the Vue version, production mode, import maps, and UI state (like showOutput or outputMode) via URL parameters or custom logic. You can also persist the REPL state to the URL hash using store.serialize().
<script setup>
import { watchEffect, ref } from 'vue'
import { Repl, useStore, useVueImportMap } from '@vue/repl'
import Monaco from '@vue/repl/monaco-editor'
const query = new URLSearchParams(location.search)
const {
importMap: builtinImportMap,
vueVersion,
productionMode
} = useVueImportMap({
runtimeDev: 'cdn link to vue.runtime.esm-browser.js',
runtimeProd: 'cdn link to vue.runtime.esm-browser.prod.js',
serverRenderer: 'cdn link to server-renderer.esm-browser.js',
})
const store = useStore(
{
builtinImportMap,
vueVersion,
showOutput: ref(query.has('showOutput')),
outputMode: ref(query.get('outputMode') || 'preview'),
},
location.hash,
)
watchEffect(() => history.replaceState({}, '', store.serialize()))
vueVersion.value = '3.2.8'
productionMode.value = true
</script>
<template>
<Repl :store="store" :editor="Monaco" :showCompileOutput="true" />
</template>