Evan You 4 лет назад
Родитель
Сommit
e1e5a75540

+ 1 - 1
src/platforms/web/entry-runtime-with-compiler-esm.ts

@@ -1,4 +1,4 @@
-import Vue from './entry-runtime-with-compiler'
+import Vue from './runtime-with-compiler'
 
 export default Vue
 

+ 5 - 108
src/platforms/web/entry-runtime-with-compiler.ts

@@ -1,110 +1,7 @@
-import config from 'core/config'
-import { warn, cached } from 'core/util/index'
-import { mark, measure } from 'core/util/perf'
+import Vue from './runtime-with-compiler'
+import * as vca from 'vca/index'
+import { extend } from 'shared/util'
 
-import Vue from './runtime/index'
-import { query } from './util/index'
-import { compileToFunctions } from './compiler/index'
-import {
-  shouldDecodeNewlines,
-  shouldDecodeNewlinesForHref
-} from './util/compat'
-import type { Component } from 'typescript/component'
-import type { GlobalAPI } from 'typescript/global-api'
+extend(Vue, vca)
 
-const idToTemplate = cached(id => {
-  const el = query(id)
-  return el && el.innerHTML
-})
-
-const mount = Vue.prototype.$mount
-Vue.prototype.$mount = function (
-  el?: string | Element,
-  hydrating?: boolean
-): Component {
-  el = el && query(el)
-
-  /* istanbul ignore if */
-  if (el === document.body || el === document.documentElement) {
-    __DEV__ &&
-      warn(
-        `Do not mount Vue to <html> or <body> - mount to normal elements instead.`
-      )
-    return this
-  }
-
-  const options = this.$options
-  // resolve template/el and convert to render function
-  if (!options.render) {
-    let template = options.template
-    if (template) {
-      if (typeof template === 'string') {
-        if (template.charAt(0) === '#') {
-          template = idToTemplate(template)
-          /* istanbul ignore if */
-          if (__DEV__ && !template) {
-            warn(
-              `Template element not found or is empty: ${options.template}`,
-              this
-            )
-          }
-        }
-      } else if (template.nodeType) {
-        template = template.innerHTML
-      } else {
-        if (__DEV__) {
-          warn('invalid template option:' + template, this)
-        }
-        return this
-      }
-    } else if (el) {
-      // @ts-expect-error
-      template = getOuterHTML(el)
-    }
-    if (template) {
-      /* istanbul ignore if */
-      if (__DEV__ && config.performance && mark) {
-        mark('compile')
-      }
-
-      const { render, staticRenderFns } = compileToFunctions(
-        template,
-        {
-          outputSourceRange: __DEV__,
-          shouldDecodeNewlines,
-          shouldDecodeNewlinesForHref,
-          delimiters: options.delimiters,
-          comments: options.comments
-        },
-        this
-      )
-      options.render = render
-      options.staticRenderFns = staticRenderFns
-
-      /* istanbul ignore if */
-      if (__DEV__ && config.performance && mark) {
-        mark('compile end')
-        measure(`vue ${this._name} compile`, 'compile', 'compile end')
-      }
-    }
-  }
-  return mount.call(this, el, hydrating)
-}
-
-/**
- * Get outerHTML of elements, taking care
- * of SVG elements in IE as well.
- */
-function getOuterHTML(el: Element): string {
-  if (el.outerHTML) {
-    return el.outerHTML
-  } else {
-    const container = document.createElement('div')
-    container.appendChild(el.cloneNode(true))
-    return container.innerHTML
-  }
-}
-
-Vue.compile = compileToFunctions
-
-export default Vue as GlobalAPI
+export default Vue

+ 110 - 0
src/platforms/web/runtime-with-compiler.ts

@@ -0,0 +1,110 @@
+import config from 'core/config'
+import { warn, cached } from 'core/util/index'
+import { mark, measure } from 'core/util/perf'
+
+import Vue from './runtime/index'
+import { query } from './util/index'
+import { compileToFunctions } from './compiler/index'
+import {
+  shouldDecodeNewlines,
+  shouldDecodeNewlinesForHref
+} from './util/compat'
+import type { Component } from 'typescript/component'
+import type { GlobalAPI } from 'typescript/global-api'
+
+const idToTemplate = cached(id => {
+  const el = query(id)
+  return el && el.innerHTML
+})
+
+const mount = Vue.prototype.$mount
+Vue.prototype.$mount = function (
+  el?: string | Element,
+  hydrating?: boolean
+): Component {
+  el = el && query(el)
+
+  /* istanbul ignore if */
+  if (el === document.body || el === document.documentElement) {
+    __DEV__ &&
+      warn(
+        `Do not mount Vue to <html> or <body> - mount to normal elements instead.`
+      )
+    return this
+  }
+
+  const options = this.$options
+  // resolve template/el and convert to render function
+  if (!options.render) {
+    let template = options.template
+    if (template) {
+      if (typeof template === 'string') {
+        if (template.charAt(0) === '#') {
+          template = idToTemplate(template)
+          /* istanbul ignore if */
+          if (__DEV__ && !template) {
+            warn(
+              `Template element not found or is empty: ${options.template}`,
+              this
+            )
+          }
+        }
+      } else if (template.nodeType) {
+        template = template.innerHTML
+      } else {
+        if (__DEV__) {
+          warn('invalid template option:' + template, this)
+        }
+        return this
+      }
+    } else if (el) {
+      // @ts-expect-error
+      template = getOuterHTML(el)
+    }
+    if (template) {
+      /* istanbul ignore if */
+      if (__DEV__ && config.performance && mark) {
+        mark('compile')
+      }
+
+      const { render, staticRenderFns } = compileToFunctions(
+        template,
+        {
+          outputSourceRange: __DEV__,
+          shouldDecodeNewlines,
+          shouldDecodeNewlinesForHref,
+          delimiters: options.delimiters,
+          comments: options.comments
+        },
+        this
+      )
+      options.render = render
+      options.staticRenderFns = staticRenderFns
+
+      /* istanbul ignore if */
+      if (__DEV__ && config.performance && mark) {
+        mark('compile end')
+        measure(`vue ${this._name} compile`, 'compile', 'compile end')
+      }
+    }
+  }
+  return mount.call(this, el, hydrating)
+}
+
+/**
+ * Get outerHTML of elements, taking care
+ * of SVG elements in IE as well.
+ */
+function getOuterHTML(el: Element): string {
+  if (el.outerHTML) {
+    return el.outerHTML
+  } else {
+    const container = document.createElement('div')
+    container.appendChild(el.cloneNode(true))
+    return container.innerHTML
+  }
+}
+
+Vue.compile = compileToFunctions
+
+export default Vue as GlobalAPI