workflow: add prod/dev toggle to sfc playground
This commit is contained in:
parent
70c2d5bbc0
commit
57d3a0566f
@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vue": "3.2.33",
|
"vue": "3.2.33",
|
||||||
"@vue/repl": "^1.0.0",
|
"@vue/repl": "^1.1.0",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"jszip": "^3.6.0"
|
"jszip": "^3.6.0"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Header from './Header.vue'
|
import Header from './Header.vue'
|
||||||
import { Repl, ReplStore } from '@vue/repl'
|
import { Repl, ReplStore } from '@vue/repl'
|
||||||
import { watchEffect } from 'vue'
|
import { ref, watchEffect } from 'vue'
|
||||||
|
|
||||||
const setVH = () => {
|
const setVH = () => {
|
||||||
document.documentElement.style.setProperty('--vh', window.innerHeight + `px`)
|
document.documentElement.style.setProperty('--vh', window.innerHeight + `px`)
|
||||||
@ -9,8 +9,11 @@ const setVH = () => {
|
|||||||
window.addEventListener('resize', setVH)
|
window.addEventListener('resize', setVH)
|
||||||
setVH()
|
setVH()
|
||||||
|
|
||||||
|
const hash = location.hash.slice(1)
|
||||||
|
const useDevMode = ref(hash.startsWith('__DEV__'))
|
||||||
|
|
||||||
const store = new ReplStore({
|
const store = new ReplStore({
|
||||||
serializedState: location.hash.slice(1),
|
serializedState: useDevMode.value ? hash.slice(7) : hash,
|
||||||
defaultVueRuntimeURL: import.meta.env.PROD
|
defaultVueRuntimeURL: import.meta.env.PROD
|
||||||
? `${location.origin}/vue.runtime.esm-browser.js`
|
? `${location.origin}/vue.runtime.esm-browser.js`
|
||||||
: `${location.origin}/src/vue-dev-proxy`
|
: `${location.origin}/src/vue-dev-proxy`
|
||||||
@ -19,16 +22,28 @@ const store = new ReplStore({
|
|||||||
// enable experimental features
|
// enable experimental features
|
||||||
const sfcOptions = {
|
const sfcOptions = {
|
||||||
script: {
|
script: {
|
||||||
|
inlineTemplate: !useDevMode.value,
|
||||||
reactivityTransform: true
|
reactivityTransform: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist state
|
// persist state
|
||||||
watchEffect(() => history.replaceState({}, '', store.serialize()))
|
watchEffect(() => {
|
||||||
|
const newHash = store
|
||||||
|
.serialize()
|
||||||
|
.replace(/^#/, useDevMode.value ? `#__DEV__` : `#`)
|
||||||
|
history.replaceState({}, '', newHash)
|
||||||
|
})
|
||||||
|
|
||||||
|
function toggleDevMode() {
|
||||||
|
const dev = (useDevMode.value = !useDevMode.value)
|
||||||
|
sfcOptions.script.inlineTemplate = !dev
|
||||||
|
store.setFiles(store.getFiles())
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Header :store="store" />
|
<Header :store="store" :dev="useDevMode" @toggle-dev="toggleDevMode" />
|
||||||
<Repl
|
<Repl
|
||||||
@keydown.ctrl.s.prevent
|
@keydown.ctrl.s.prevent
|
||||||
@keydown.meta.s.prevent
|
@keydown.meta.s.prevent
|
||||||
|
@ -8,7 +8,8 @@ import Download from './icons/Download.vue'
|
|||||||
import GitHub from './icons/GitHub.vue'
|
import GitHub from './icons/GitHub.vue'
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { store } = defineProps(['store'])
|
const props = defineProps(['store', 'dev'])
|
||||||
|
const { store } = props
|
||||||
|
|
||||||
const currentCommit = __COMMIT__
|
const currentCommit = __COMMIT__
|
||||||
const activeVersion = ref(`@${currentCommit}`)
|
const activeVersion = ref(`@${currentCommit}`)
|
||||||
@ -112,6 +113,14 @@ async function fetchVersions(): Promise<string[]> {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
title="Toggle development production mode"
|
||||||
|
class="toggle-dev"
|
||||||
|
:class="{ dev }"
|
||||||
|
@click="$emit('toggle-dev')"
|
||||||
|
>
|
||||||
|
{{ dev ? 'DEV' : 'PROD' }}
|
||||||
|
</button>
|
||||||
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
|
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
|
||||||
<Sun class="light" />
|
<Sun class="light" />
|
||||||
<Moon class="dark" />
|
<Moon class="dark" />
|
||||||
@ -126,13 +135,10 @@ async function fetchVersions(): Promise<string[]> {
|
|||||||
>
|
>
|
||||||
<Download />
|
<Download />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button title="View on GitHub" class="github">
|
||||||
title="View on GitHub"
|
|
||||||
class="github"
|
|
||||||
>
|
|
||||||
<a
|
<a
|
||||||
href="https://github.com/vuejs/core/tree/main/packages/sfc-playground"
|
href="https://github.com/vuejs/core/tree/main/packages/sfc-playground"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<GitHub />
|
<GitHub />
|
||||||
</a>
|
</a>
|
||||||
@ -228,6 +234,16 @@ h1 img {
|
|||||||
top: 22px;
|
top: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toggle-dev {
|
||||||
|
color: #f07178;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: var(--nav-height);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-dev.dev {
|
||||||
|
color: #c3e88d;
|
||||||
|
}
|
||||||
|
|
||||||
.toggle-dark svg {
|
.toggle-dark svg {
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
|
@ -242,13 +242,13 @@ importers:
|
|||||||
packages/sfc-playground:
|
packages/sfc-playground:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@vitejs/plugin-vue': ^1.10.2
|
'@vitejs/plugin-vue': ^1.10.2
|
||||||
'@vue/repl': ^1.0.0
|
'@vue/repl': ^1.1.0
|
||||||
file-saver: ^2.0.5
|
file-saver: ^2.0.5
|
||||||
jszip: ^3.6.0
|
jszip: ^3.6.0
|
||||||
vite: ^2.9.8
|
vite: ^2.9.8
|
||||||
vue: 3.2.33
|
vue: 3.2.33
|
||||||
dependencies:
|
dependencies:
|
||||||
'@vue/repl': 1.0.0_vue@packages+vue
|
'@vue/repl': 1.1.0_vue@packages+vue
|
||||||
file-saver: 2.0.5
|
file-saver: 2.0.5
|
||||||
jszip: 3.7.1
|
jszip: 3.7.1
|
||||||
vue: link:../vue
|
vue: link:../vue
|
||||||
@ -1349,8 +1349,8 @@ packages:
|
|||||||
engines: {node: '>= 0.12.0'}
|
engines: {node: '>= 0.12.0'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@vue/repl/1.0.0_vue@packages+vue:
|
/@vue/repl/1.1.0_vue@packages+vue:
|
||||||
resolution: {integrity: sha512-cDcQuWKZuA0Y0JYEpiQS/ZAEGP/RrfkcK+zKm5H8tUjfD8XIxYHY+sQGoY6FSkz/gAOQJocrsaPgt7ddKL0inQ==}
|
resolution: {integrity: sha512-qmu05PZdBtdkSacQgRdqmOnRbzJZlryee/d6OFZfRMwthHI8Ek3GLvTXkSAzhjgWXdENBPOBIoYW3gOZTVfNzA==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
vue: ^3.2.13
|
vue: ^3.2.13
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user