Skip to content

Commit fc79029

Browse files
committed
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.
1 parent d558518 commit fc79029

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dev-sfc": "run-s dev-sfc-prepare dev-sfc-run",
3030
"dev-sfc-prepare": "node scripts/pre-dev-sfc.js || npm run build-all-cjs",
3131
"dev-sfc-serve": "vite packages/sfc-playground --host",
32-
"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",
32+
"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",
3333
"serve": "serve",
3434
"open": "open http://localhost:3000/packages/template-explorer/local.html",
3535
"build-sfc-playground": "run-s build-all-cjs build-runtime-esm build-ssr-esm build-sfc-playground-self",

packages/sfc-playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"vite": "^4.5.0"
1414
},
1515
"dependencies": {
16-
"@vue/repl": "^2.6.3",
16+
"@vue/repl": "^2.7.0",
1717
"file-saver": "^2.0.5",
1818
"jszip": "^3.10.1",
1919
"vue": "workspace:*"

packages/sfc-playground/src/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ if (hash.startsWith('__SSR__')) {
2525
2626
const store = new ReplStore({
2727
serializedState: hash,
28+
productionMode: !useDevMode.value,
2829
defaultVueRuntimeURL: import.meta.env.PROD
2930
? `${location.origin}/vue.runtime.esm-browser.js`
3031
: `${location.origin}/src/vue-dev-proxy`,
32+
defaultVueRuntimeProdURL: import.meta.env.PROD
33+
? `${location.origin}/vue.runtime.esm-browser.prod.js`
34+
: `${location.origin}/src/vue-dev-proxy-prod`,
3135
defaultVueServerRendererURL: import.meta.env.PROD
3236
? `${location.origin}/server-renderer.esm-browser.js`
3337
: `${location.origin}/src/vue-server-renderer-dev-proxy`
@@ -65,7 +69,7 @@ function toggleDevMode() {
6569
sfcOptions.template!.isProd =
6670
sfcOptions.style!.isProd =
6771
!dev
68-
store.setFiles(store.getFiles())
72+
store.toggleProduction()
6973
}
7074
7175
function toggleSSR() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// serve vue to the iframe sandbox during dev.
2+
// @ts-ignore
3+
export * from 'vue/dist/vue.runtime.esm-browser.prod.js'

packages/sfc-playground/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function copyVuePlugin(): Plugin {
4949
}
5050

5151
copyFile(`../vue/dist/vue.runtime.esm-browser.js`)
52+
copyFile(`../vue/dist/vue.runtime.esm-browser.prod.js`)
5253
copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
5354
}
5455
}

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/dev.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
1616
const args = minimist(process.argv.slice(2))
1717
const target = args._[0] || 'vue'
1818
const format = args.f || 'global'
19+
const prod = args.p || false
1920
const inlineDeps = args.i || args.inline
2021
const pkg = require(`../packages/${target}/package.json`)
2122

@@ -34,7 +35,7 @@ const outfile = resolve(
3435
__dirname,
3536
`../packages/${target}/dist/${
3637
target === 'vue-compat' ? `vue` : target
37-
}.${postfix}.js`
38+
}.${postfix}.${prod ? `prod.` : ``}js`
3839
)
3940
const relativeOutfile = relative(process.cwd(), outfile)
4041

@@ -109,7 +110,7 @@ esbuild
109110
define: {
110111
__COMMIT__: `"dev"`,
111112
__VERSION__: `"${pkg.version}"`,
112-
__DEV__: `true`,
113+
__DEV__: prod ? `false` : `true`,
113114
__TEST__: `false`,
114115
__BROWSER__: String(
115116
format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches

0 commit comments

Comments
 (0)