|
@@ -4,6 +4,9 @@ import { extend, generateCodeFrame, isFunction, NO } from '@vue/shared'
|
|
|
import { CompilerError, CompilerOptions } from '@vue/compiler-core'
|
|
import { CompilerError, CompilerOptions } from '@vue/compiler-core'
|
|
|
import { PushFn } from '../render'
|
|
import { PushFn } from '../render'
|
|
|
|
|
|
|
|
|
|
+import * as Vue from 'vue'
|
|
|
|
|
+import * as helpers from '../internal'
|
|
|
|
|
+
|
|
|
type SSRRenderFunction = (
|
|
type SSRRenderFunction = (
|
|
|
context: any,
|
|
context: any,
|
|
|
push: PushFn,
|
|
push: PushFn,
|
|
@@ -16,6 +19,7 @@ export function ssrCompile(
|
|
|
template: string,
|
|
template: string,
|
|
|
instance: ComponentInternalInstance
|
|
instance: ComponentInternalInstance
|
|
|
): SSRRenderFunction {
|
|
): SSRRenderFunction {
|
|
|
|
|
+ // TODO: this branch should now work in ESM builds, enable it in a minor
|
|
|
if (!__NODE_JS__) {
|
|
if (!__NODE_JS__) {
|
|
|
throw new Error(
|
|
throw new Error(
|
|
|
`On-the-fly template compilation is not supported in the ESM build of ` +
|
|
`On-the-fly template compilation is not supported in the ESM build of ` +
|
|
@@ -76,5 +80,10 @@ export function ssrCompile(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const { code } = compile(template, finalCompilerOptions)
|
|
const { code } = compile(template, finalCompilerOptions)
|
|
|
- return (compileCache[cacheKey] = Function('require', code)(require))
|
|
|
|
|
|
|
+ const requireMap = {
|
|
|
|
|
+ vue: Vue,
|
|
|
|
|
+ 'vue/server-renderer': helpers
|
|
|
|
|
+ }
|
|
|
|
|
+ const fakeRequire = (id: 'vue' | 'vue/server-renderer') => requireMap[id]
|
|
|
|
|
+ return (compileCache[cacheKey] = Function('require', code)(fakeRequire))
|
|
|
}
|
|
}
|