]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: expose vapor aliases in non-vapor runtime entries
authordaiwei <daiwei521@126.com>
Tue, 14 Oct 2025 13:24:55 +0000 (21:24 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 15 Oct 2025 02:06:48 +0000 (10:06 +0800)
It captures the essence—standard entries now re-export the Vapor APIs
via aliases so SSR keeps working without the Vapor runtime.

packages/vue/src/index-with-vapor.ts
packages/vue/src/index.ts
packages/vue/src/indexBase.ts [new file with mode: 0644]
packages/vue/src/runtime-with-vapor.ts
packages/vue/src/runtime.ts
packages/vue/src/runtimeBase.ts [new file with mode: 0644]
packages/vue/src/vaporAliases.ts [new file with mode: 0644]

index 21f4c8073cfda0496534132f60499fe439775218..9e139113ced83ace7a08ffa15f085dc768ecafa7 100644 (file)
@@ -1,3 +1,3 @@
 // for type generation only
-export * from './index'
+export * from './indexBase'
 export * from '@vue/runtime-vapor'
index 785f3fd4bb4fa8ee0c1b6bc8699d362610e4cb79..8d2de8d30158eb3ded824eccae340107ad3b0d1c 100644 (file)
@@ -1,107 +1,2 @@
-// This entry is the "full-build" that includes both the runtime
-// and the compiler, and supports on-the-fly compilation of the template option.
-import { initDev } from './dev'
-import {
-  type CompilerError,
-  type CompilerOptions,
-  compile,
-} from '@vue/compiler-dom'
-import {
-  type RenderFunction,
-  registerRuntimeCompiler,
-  warn,
-} from '@vue/runtime-dom'
-import * as runtimeDom from '@vue/runtime-dom'
-import {
-  NOOP,
-  extend,
-  genCacheKey,
-  generateCodeFrame,
-  isString,
-} from '@vue/shared'
-import type { InternalRenderFunction } from 'packages/runtime-core/src/component'
-
-if (__DEV__) {
-  initDev()
-}
-
-const compileCache: Record<string, RenderFunction> = Object.create(null)
-
-function compileToFunction(
-  template: string | HTMLElement,
-  options?: CompilerOptions,
-): RenderFunction {
-  if (!isString(template)) {
-    if (template.nodeType) {
-      template = template.innerHTML
-    } else {
-      __DEV__ && warn(`invalid template option: `, template)
-      return NOOP
-    }
-  }
-
-  const key = genCacheKey(template, options)
-  const cached = compileCache[key]
-  if (cached) {
-    return cached
-  }
-
-  if (template[0] === '#') {
-    const el = document.querySelector(template)
-    if (__DEV__ && !el) {
-      warn(`Template element not found or is empty: ${template}`)
-    }
-    // __UNSAFE__
-    // Reason: potential execution of JS expressions in in-DOM template.
-    // The user must make sure the in-DOM template is trusted. If it's rendered
-    // by the server, the template should not contain any user data.
-    template = el ? el.innerHTML : ``
-  }
-
-  const opts = extend(
-    {
-      hoistStatic: true,
-      onError: __DEV__ ? onError : undefined,
-      onWarn: __DEV__ ? e => onError(e, true) : NOOP,
-    } as CompilerOptions,
-    options,
-  )
-
-  if (!opts.isCustomElement && typeof customElements !== 'undefined') {
-    opts.isCustomElement = tag => !!customElements.get(tag)
-  }
-
-  const { code } = compile(template, opts)
-
-  function onError(err: CompilerError, asWarning = false) {
-    const message = asWarning
-      ? err.message
-      : `Template compilation error: ${err.message}`
-    const codeFrame =
-      err.loc &&
-      generateCodeFrame(
-        template as string,
-        err.loc.start.offset,
-        err.loc.end.offset,
-      )
-    warn(codeFrame ? `${message}\n${codeFrame}` : message)
-  }
-
-  // The wildcard import results in a huge object with every export
-  // with keys that cannot be mangled, and can be quite heavy size-wise.
-  // In the global build we know `Vue` is available globally so we can avoid
-  // the wildcard object.
-  const render = (
-    __GLOBAL__ ? new Function(code)() : new Function('Vue', code)(runtimeDom)
-  ) as RenderFunction
-
-  // mark the function as runtime compiled
-  ;(render as InternalRenderFunction)._rc = true
-
-  return (compileCache[key] = render)
-}
-
-registerRuntimeCompiler(compileToFunction)
-
-export { compileToFunction as compile }
-export * from '@vue/runtime-dom'
+export * from './indexBase'
+export * from './vaporAliases'
diff --git a/packages/vue/src/indexBase.ts b/packages/vue/src/indexBase.ts
new file mode 100644 (file)
index 0000000..785f3fd
--- /dev/null
@@ -0,0 +1,107 @@
+// This entry is the "full-build" that includes both the runtime
+// and the compiler, and supports on-the-fly compilation of the template option.
+import { initDev } from './dev'
+import {
+  type CompilerError,
+  type CompilerOptions,
+  compile,
+} from '@vue/compiler-dom'
+import {
+  type RenderFunction,
+  registerRuntimeCompiler,
+  warn,
+} from '@vue/runtime-dom'
+import * as runtimeDom from '@vue/runtime-dom'
+import {
+  NOOP,
+  extend,
+  genCacheKey,
+  generateCodeFrame,
+  isString,
+} from '@vue/shared'
+import type { InternalRenderFunction } from 'packages/runtime-core/src/component'
+
+if (__DEV__) {
+  initDev()
+}
+
+const compileCache: Record<string, RenderFunction> = Object.create(null)
+
+function compileToFunction(
+  template: string | HTMLElement,
+  options?: CompilerOptions,
+): RenderFunction {
+  if (!isString(template)) {
+    if (template.nodeType) {
+      template = template.innerHTML
+    } else {
+      __DEV__ && warn(`invalid template option: `, template)
+      return NOOP
+    }
+  }
+
+  const key = genCacheKey(template, options)
+  const cached = compileCache[key]
+  if (cached) {
+    return cached
+  }
+
+  if (template[0] === '#') {
+    const el = document.querySelector(template)
+    if (__DEV__ && !el) {
+      warn(`Template element not found or is empty: ${template}`)
+    }
+    // __UNSAFE__
+    // Reason: potential execution of JS expressions in in-DOM template.
+    // The user must make sure the in-DOM template is trusted. If it's rendered
+    // by the server, the template should not contain any user data.
+    template = el ? el.innerHTML : ``
+  }
+
+  const opts = extend(
+    {
+      hoistStatic: true,
+      onError: __DEV__ ? onError : undefined,
+      onWarn: __DEV__ ? e => onError(e, true) : NOOP,
+    } as CompilerOptions,
+    options,
+  )
+
+  if (!opts.isCustomElement && typeof customElements !== 'undefined') {
+    opts.isCustomElement = tag => !!customElements.get(tag)
+  }
+
+  const { code } = compile(template, opts)
+
+  function onError(err: CompilerError, asWarning = false) {
+    const message = asWarning
+      ? err.message
+      : `Template compilation error: ${err.message}`
+    const codeFrame =
+      err.loc &&
+      generateCodeFrame(
+        template as string,
+        err.loc.start.offset,
+        err.loc.end.offset,
+      )
+    warn(codeFrame ? `${message}\n${codeFrame}` : message)
+  }
+
+  // The wildcard import results in a huge object with every export
+  // with keys that cannot be mangled, and can be quite heavy size-wise.
+  // In the global build we know `Vue` is available globally so we can avoid
+  // the wildcard object.
+  const render = (
+    __GLOBAL__ ? new Function(code)() : new Function('Vue', code)(runtimeDom)
+  ) as RenderFunction
+
+  // mark the function as runtime compiled
+  ;(render as InternalRenderFunction)._rc = true
+
+  return (compileCache[key] = render)
+}
+
+registerRuntimeCompiler(compileToFunction)
+
+export { compileToFunction as compile }
+export * from '@vue/runtime-dom'
index 4f03329ede4c39cef6a3e11f5e14c0d69859941c..eee717fc130564729f3774e299c5136165223e68 100644 (file)
@@ -1,2 +1,2 @@
-export * from './runtime'
+export * from './runtimeBase'
 export * from '@vue/runtime-vapor'
index af1ffe7a12a09ade54d6a8675176ac8c20b287f6..1c81ab0badf1a1f98cd2f235b7d5986e90668537 100644 (file)
@@ -1,27 +1,2 @@
-// This entry exports the runtime only, and is built as
-// `dist/vue.esm-bundler.js` which is used by default for bundlers.
-import { NOOP } from '@vue/shared'
-import { initDev } from './dev'
-import { type RenderFunction, warn } from '@vue/runtime-dom'
-
-if (__DEV__) {
-  initDev()
-}
-
-export * from '@vue/runtime-dom'
-
-export const compile = (_template: string): RenderFunction => {
-  if (__DEV__) {
-    warn(
-      `Runtime compilation is not supported in this build of Vue.` +
-        (__ESM_BUNDLER__
-          ? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
-          : __ESM_BROWSER__
-            ? ` Use "vue.esm-browser.js" instead.`
-            : __GLOBAL__
-              ? ` Use "vue.global.js" instead.`
-              : ``) /* should not happen */,
-    )
-  }
-  return NOOP
-}
+export * from './runtimeBase'
+export * from './vaporAliases'
diff --git a/packages/vue/src/runtimeBase.ts b/packages/vue/src/runtimeBase.ts
new file mode 100644 (file)
index 0000000..af1ffe7
--- /dev/null
@@ -0,0 +1,27 @@
+// This entry exports the runtime only, and is built as
+// `dist/vue.esm-bundler.js` which is used by default for bundlers.
+import { NOOP } from '@vue/shared'
+import { initDev } from './dev'
+import { type RenderFunction, warn } from '@vue/runtime-dom'
+
+if (__DEV__) {
+  initDev()
+}
+
+export * from '@vue/runtime-dom'
+
+export const compile = (_template: string): RenderFunction => {
+  if (__DEV__) {
+    warn(
+      `Runtime compilation is not supported in this build of Vue.` +
+        (__ESM_BUNDLER__
+          ? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
+          : __ESM_BROWSER__
+            ? ` Use "vue.esm-browser.js" instead.`
+            : __GLOBAL__
+              ? ` Use "vue.global.js" instead.`
+              : ``) /* should not happen */,
+    )
+  }
+  return NOOP
+}
diff --git a/packages/vue/src/vaporAliases.ts b/packages/vue/src/vaporAliases.ts
new file mode 100644 (file)
index 0000000..f426d9d
--- /dev/null
@@ -0,0 +1,7 @@
+// Vapor-only APIs do not exist in the standard build, yet SSR executes
+// the standard entry. We alias them to the core implementations so SSR
+// keeps working without the Vapor runtime.
+export {
+  defineAsyncComponent as defineVaporAsyncComponent,
+  defineComponent as defineVaporComponent,
+} from '@vue/runtime-core'