workflow(playground): prod/dev toggle should apply to runtime behavior as well

Previously, the prod/dev toggle in the SFC playground only affects the
SFC compiation behavior, but not the actual runtime. This can make it
confusing when users are trying to reproduce prod/dev behavior
inconsistency in the runtime code instead of the compiler.
This commit is contained in:
Evan You 2023-11-12 16:30:30 +08:00
parent d5585184a1
commit fc7902982a
7 changed files with 18 additions and 9 deletions

View File

@ -29,7 +29,7 @@
"dev-sfc": "run-s dev-sfc-prepare dev-sfc-run", "dev-sfc": "run-s dev-sfc-prepare dev-sfc-run",
"dev-sfc-prepare": "node scripts/pre-dev-sfc.js || npm run build-all-cjs", "dev-sfc-prepare": "node scripts/pre-dev-sfc.js || npm run build-all-cjs",
"dev-sfc-serve": "vite packages/sfc-playground --host", "dev-sfc-serve": "vite packages/sfc-playground --host",
"dev-sfc-run": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev server-renderer -if esm-bundler\" dev-sfc-serve", "dev-sfc-run": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev vue -ipf esm-browser-runtime\" \"dev server-renderer -if esm-bundler\" dev-sfc-serve",
"serve": "serve", "serve": "serve",
"open": "open http://localhost:3000/packages/template-explorer/local.html", "open": "open http://localhost:3000/packages/template-explorer/local.html",
"build-sfc-playground": "run-s build-all-cjs build-runtime-esm build-ssr-esm build-sfc-playground-self", "build-sfc-playground": "run-s build-all-cjs build-runtime-esm build-ssr-esm build-sfc-playground-self",

View File

@ -13,7 +13,7 @@
"vite": "^4.5.0" "vite": "^4.5.0"
}, },
"dependencies": { "dependencies": {
"@vue/repl": "^2.6.3", "@vue/repl": "^2.7.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"vue": "workspace:*" "vue": "workspace:*"

View File

@ -25,9 +25,13 @@ if (hash.startsWith('__SSR__')) {
const store = new ReplStore({ const store = new ReplStore({
serializedState: hash, serializedState: hash,
productionMode: !useDevMode.value,
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`,
defaultVueRuntimeProdURL: import.meta.env.PROD
? `${location.origin}/vue.runtime.esm-browser.prod.js`
: `${location.origin}/src/vue-dev-proxy-prod`,
defaultVueServerRendererURL: import.meta.env.PROD defaultVueServerRendererURL: import.meta.env.PROD
? `${location.origin}/server-renderer.esm-browser.js` ? `${location.origin}/server-renderer.esm-browser.js`
: `${location.origin}/src/vue-server-renderer-dev-proxy` : `${location.origin}/src/vue-server-renderer-dev-proxy`
@ -65,7 +69,7 @@ function toggleDevMode() {
sfcOptions.template!.isProd = sfcOptions.template!.isProd =
sfcOptions.style!.isProd = sfcOptions.style!.isProd =
!dev !dev
store.setFiles(store.getFiles()) store.toggleProduction()
} }
function toggleSSR() { function toggleSSR() {

View File

@ -0,0 +1,3 @@
// serve vue to the iframe sandbox during dev.
// @ts-ignore
export * from 'vue/dist/vue.runtime.esm-browser.prod.js'

View File

@ -49,6 +49,7 @@ function copyVuePlugin(): Plugin {
} }
copyFile(`../vue/dist/vue.runtime.esm-browser.js`) copyFile(`../vue/dist/vue.runtime.esm-browser.js`)
copyFile(`../vue/dist/vue.runtime.esm-browser.prod.js`)
copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`) copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
} }
} }

View File

@ -354,8 +354,8 @@ importers:
packages/sfc-playground: packages/sfc-playground:
dependencies: dependencies:
'@vue/repl': '@vue/repl':
specifier: ^2.6.3 specifier: ^2.7.0
version: 2.6.3 version: 2.7.0
file-saver: file-saver:
specifier: ^2.0.5 specifier: ^2.0.5
version: 2.0.5 version: 2.0.5
@ -1669,8 +1669,8 @@ packages:
engines: {node: '>= 0.12.0'} engines: {node: '>= 0.12.0'}
dev: true dev: true
/@vue/repl@2.6.3: /@vue/repl@2.7.0:
resolution: {integrity: sha512-iUlgIMJtZ3+HUqkZhYw8WH0MTfElCEVu5Inr/LyqnpkoSDkZJk8nMFR3AV+xrDC6+HDwiRYnnTmDux84GJUP7A==} resolution: {integrity: sha512-zzyb+tVvzmOePv8Gp4sefP/7CKidx4WiJDfKPP698b9bN5jSFtmSOg4nvPoJEE1ICKeAEgdRKVneYJ8Mp7C/WA==}
dev: false dev: false
/@zeit/schemas@2.29.0: /@zeit/schemas@2.29.0:

View File

@ -16,6 +16,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
const args = minimist(process.argv.slice(2)) const args = minimist(process.argv.slice(2))
const target = args._[0] || 'vue' const target = args._[0] || 'vue'
const format = args.f || 'global' const format = args.f || 'global'
const prod = args.p || false
const inlineDeps = args.i || args.inline const inlineDeps = args.i || args.inline
const pkg = require(`../packages/${target}/package.json`) const pkg = require(`../packages/${target}/package.json`)
@ -34,7 +35,7 @@ const outfile = resolve(
__dirname, __dirname,
`../packages/${target}/dist/${ `../packages/${target}/dist/${
target === 'vue-compat' ? `vue` : target target === 'vue-compat' ? `vue` : target
}.${postfix}.js` }.${postfix}.${prod ? `prod.` : ``}js`
) )
const relativeOutfile = relative(process.cwd(), outfile) const relativeOutfile = relative(process.cwd(), outfile)
@ -109,7 +110,7 @@ esbuild
define: { define: {
__COMMIT__: `"dev"`, __COMMIT__: `"dev"`,
__VERSION__: `"${pkg.version}"`, __VERSION__: `"${pkg.version}"`,
__DEV__: `true`, __DEV__: prod ? `false` : `true`,
__TEST__: `false`, __TEST__: `false`,
__BROWSER__: String( __BROWSER__: String(
format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches