vue3-yuanma/packages/vue/src/index.ts
Stanislav Lashmanov b7a9c25f14 fix: expose Vue to compiled template (#120)
This removes the reliance on `Vue` being exposed as a global.
2019-10-06 11:38:05 -04:00

29 lines
917 B
TypeScript

// This package is the "full-build" that includes both the runtime
// and the compiler, and supports on-the-fly compilation of the template option.
import { compile, CompilerOptions } from '@vue/compiler-dom'
import * as runtimeDom from '@vue/runtime-dom'
import { registerRuntimeCompiler, RenderFunction } from '@vue/runtime-dom'
function compileToFunction(
template: string,
options?: CompilerOptions
): RenderFunction {
const { code } = compile(template, {
hoistStatic: true,
...options
})
return new Function('Vue', code)(runtimeDom) as RenderFunction
}
registerRuntimeCompiler(compileToFunction)
export { compileToFunction as compile }
export * from '@vue/runtime-dom'
if (__BROWSER__ && __DEV__) {
console[console.info ? 'info' : 'log'](
`You are running a development build of Vue.\n` +
`Make sure to use the production build (*.prod.js) when deploying for production.`
)
}