1 Star 4 Fork 0

李金文/vue-next学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.ts 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
李金文 提交于 6年前 . first commit
// 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 { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
import * as runtimeDom from '@vue/runtime-dom'
import { isString, NOOP } from '@vue/shared'
const idToTemplateCache = Object.create(null)
function compileToFunction(
template: string | HTMLElement,
options?: CompilerOptions
): RenderFunction {
if (isString(template)) {
if (template[0] === '#') {
if (template in idToTemplateCache) {
template = idToTemplateCache[template]
} else {
const el = document.querySelector(template)
if (__DEV__ && !el) {
warn(`Template element not found or is empty: ${template}`)
}
template = idToTemplateCache[template] = el ? el.innerHTML : ``
}
}
} else if (template.nodeType) {
template = template.innerHTML
} else {
__DEV__ && warn(`invalid template option: `, template)
return NOOP
}
const { code } = compile(template as string, {
hoistStatic: true,
cacheHandlers: 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.`
)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kennana/vue_next_learning.git
git@gitee.com:kennana/vue_next_learning.git
kennana
vue_next_learning
vue-next学习
master

搜索帮助