workflow: support ssr repros in sfc playground
This commit is contained in:
parent
90308e893b
commit
ec2856c2ba
@ -20,12 +20,12 @@
|
|||||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||||
"dev-esm": "node scripts/dev.js -if esm-bundler-runtime",
|
"dev-esm": "node scripts/dev.js -if esm-bundler-runtime",
|
||||||
"dev-compiler": "run-p \"dev template-explorer\" serve",
|
"dev-compiler": "run-p \"dev template-explorer\" serve",
|
||||||
"dev-sfc": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime \" serve-sfc-playground",
|
"dev-sfc": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev server-renderer -if esm-bundler\" serve-sfc-playground",
|
||||||
"serve-sfc-playground": "vite packages/sfc-playground --host",
|
"serve-sfc-playground": "vite packages/sfc-playground --host",
|
||||||
"serve": "serve",
|
"serve": "serve",
|
||||||
"open": "open http://localhost:5000/packages/template-explorer/local.html",
|
"open": "open http://localhost:5000/packages/template-explorer/local.html",
|
||||||
"preinstall": "node ./scripts/preinstall.js",
|
"preinstall": "node ./scripts/preinstall.js",
|
||||||
"prebuild-sfc-playground": "node scripts/build.js compiler reactivity-transform shared -af cjs && node scripts/build.js runtime reactivity shared -af esm-bundler && node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js vue -f esm-browser-runtime && node scripts/build.js compiler-sfc -f esm-browser",
|
"prebuild-sfc-playground": "node scripts/build.js compiler reactivity-transform shared -af cjs && node scripts/build.js runtime reactivity shared -af esm-bundler && node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js vue -f esm-browser-runtime && node scripts/build.js compiler-sfc server-renderer -f esm-browser",
|
||||||
"build-sfc-playground": "cd packages/sfc-playground && npm run build"
|
"build-sfc-playground": "cd packages/sfc-playground && npm run build"
|
||||||
},
|
},
|
||||||
"types": "test-dts/index.d.ts",
|
"types": "test-dts/index.d.ts",
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vue": "3.2.36",
|
"vue": "3.2.36",
|
||||||
"@vue/repl": "^1.1.2",
|
"@vue/repl": "^1.2.4",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"jszip": "^3.6.0"
|
"jszip": "^3.6.0"
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,27 @@ const setVH = () => {
|
|||||||
window.addEventListener('resize', setVH)
|
window.addEventListener('resize', setVH)
|
||||||
setVH()
|
setVH()
|
||||||
|
|
||||||
const hash = location.hash.slice(1)
|
const useDevMode = ref(false)
|
||||||
const useDevMode = ref(hash.startsWith('__DEV__'))
|
const useSSRMode = ref(false)
|
||||||
|
|
||||||
|
let hash = location.hash.slice(1)
|
||||||
|
if (hash.startsWith('__DEV__')) {
|
||||||
|
hash = hash.slice(7)
|
||||||
|
useDevMode.value = true
|
||||||
|
}
|
||||||
|
if (hash.startsWith('__SSR__')) {
|
||||||
|
hash = hash.slice(7)
|
||||||
|
useSSRMode.value = true
|
||||||
|
}
|
||||||
|
|
||||||
const store = new ReplStore({
|
const store = new ReplStore({
|
||||||
serializedState: useDevMode.value ? hash.slice(7) : hash,
|
serializedState: 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`,
|
||||||
|
defaultVueServerRendererURL: import.meta.env.PROD
|
||||||
|
? `${location.origin}/server-renderer.esm-browser.js`
|
||||||
|
: `${location.origin}/src/vue-server-renderer-dev-proxy`
|
||||||
})
|
})
|
||||||
|
|
||||||
// enable experimental features
|
// enable experimental features
|
||||||
@ -31,6 +44,7 @@ const sfcOptions = {
|
|||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
const newHash = store
|
const newHash = store
|
||||||
.serialize()
|
.serialize()
|
||||||
|
.replace(/^#/, useSSRMode.value ? `#__SSR__` : `#`)
|
||||||
.replace(/^#/, useDevMode.value ? `#__DEV__` : `#`)
|
.replace(/^#/, useDevMode.value ? `#__DEV__` : `#`)
|
||||||
history.replaceState({}, '', newHash)
|
history.replaceState({}, '', newHash)
|
||||||
})
|
})
|
||||||
@ -40,13 +54,25 @@ function toggleDevMode() {
|
|||||||
sfcOptions.script.inlineTemplate = !dev
|
sfcOptions.script.inlineTemplate = !dev
|
||||||
store.setFiles(store.getFiles())
|
store.setFiles(store.getFiles())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleSSR() {
|
||||||
|
useSSRMode.value = !useSSRMode.value
|
||||||
|
store.setFiles(store.getFiles())
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Header :store="store" :dev="useDevMode" @toggle-dev="toggleDevMode" />
|
<Header
|
||||||
|
:store="store"
|
||||||
|
:dev="useDevMode"
|
||||||
|
:ssr="useSSRMode"
|
||||||
|
@toggle-dev="toggleDevMode"
|
||||||
|
@toggle-ssr="toggleSSR"
|
||||||
|
/>
|
||||||
<Repl
|
<Repl
|
||||||
@keydown.ctrl.s.prevent
|
@keydown.ctrl.s.prevent
|
||||||
@keydown.meta.s.prevent
|
@keydown.meta.s.prevent
|
||||||
|
:ssr="useSSRMode"
|
||||||
:store="store"
|
:store="store"
|
||||||
:showCompileOutput="true"
|
:showCompileOutput="true"
|
||||||
:autoResize="true"
|
:autoResize="true"
|
||||||
|
@ -8,7 +8,7 @@ import Download from './icons/Download.vue'
|
|||||||
import GitHub from './icons/GitHub.vue'
|
import GitHub from './icons/GitHub.vue'
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const props = defineProps(['store', 'dev'])
|
const props = defineProps(['store', 'dev', 'ssr'])
|
||||||
const { store } = props
|
const { store } = props
|
||||||
|
|
||||||
const currentCommit = __COMMIT__
|
const currentCommit = __COMMIT__
|
||||||
@ -122,6 +122,14 @@ async function fetchVersions(): Promise<string[]> {
|
|||||||
>
|
>
|
||||||
<span>{{ dev ? 'DEV' : 'PROD' }}</span>
|
<span>{{ dev ? 'DEV' : 'PROD' }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
title="Toggle server rendering mode"
|
||||||
|
class="toggle-ssr"
|
||||||
|
:class="{ enabled: ssr }"
|
||||||
|
@click="$emit('toggle-ssr')"
|
||||||
|
>
|
||||||
|
<span>{{ ssr ? 'SSR ON' : 'SSR OFF' }}</span>
|
||||||
|
</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" />
|
||||||
@ -156,7 +164,7 @@ nav {
|
|||||||
--btn: #666;
|
--btn: #666;
|
||||||
--highlight: #333;
|
--highlight: #333;
|
||||||
--green: #3ca877;
|
--green: #3ca877;
|
||||||
--red: #f07178;
|
--purple: #904cbc;
|
||||||
|
|
||||||
color: var(--base);
|
color: var(--base);
|
||||||
height: var(--nav-height);
|
height: var(--nav-height);
|
||||||
@ -235,18 +243,31 @@ h1 img {
|
|||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle-dev span {
|
.toggle-dev span,
|
||||||
|
.toggle-ssr span {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
background: var(--red);
|
|
||||||
color: #fff;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 4px 6px;
|
padding: 4px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toggle-dev span {
|
||||||
|
background: var(--purple);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.toggle-dev.dev span {
|
.toggle-dev.dev span {
|
||||||
background: var(--green);
|
background: var(--green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toggle-ssr span {
|
||||||
|
background-color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-ssr.enabled span {
|
||||||
|
color: #fff;
|
||||||
|
background-color: var(--green);
|
||||||
|
}
|
||||||
|
|
||||||
.toggle-dark svg {
|
.toggle-dark svg {
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
// serve vue/server-renderer to the iframe sandbox during dev.
|
||||||
|
export * from 'vue/server-renderer'
|
@ -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.1.2
|
'@vue/repl': ^1.2.4
|
||||||
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.36
|
vue: 3.2.36
|
||||||
dependencies:
|
dependencies:
|
||||||
'@vue/repl': 1.1.2_vue@packages+vue
|
'@vue/repl': 1.2.4_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.1.2_vue@packages+vue:
|
/@vue/repl/1.2.4_vue@packages+vue:
|
||||||
resolution: {integrity: sha512-IYcoKZgwdn6spiVwGuWeXAbqAv3Nhjc/0dKEJ3BT5U6kV7KLLCwnuizjOvV8P+yFmtsfNkWbmWv9/56Pv5rH/w==}
|
resolution: {integrity: sha512-qmM4eIFQoz85gmHzBzcDwL0Tq3o1SBtT/HXvq6z6Co42AruKQFqle6LHo/XV9DJA+sPxHAQyBkuMXmokQ4vGsg==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
vue: ^3.2.13
|
vue: ^3.2.13
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user