index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* @flow */
  2. import Vue from 'core/index'
  3. import config from 'core/config'
  4. import { extend, noop } from 'shared/util'
  5. import { mountComponent } from 'core/instance/lifecycle'
  6. import { devtools, inBrowser, isChrome } from 'core/util/index'
  7. import {
  8. query,
  9. mustUseProp,
  10. isReservedTag,
  11. isReservedAttr,
  12. getTagNamespace,
  13. isUnknownElement
  14. } from 'web/util/index'
  15. import { patch } from './patch'
  16. import platformDirectives from './directives/index'
  17. import platformComponents from './components/index'
  18. // install platform specific utils
  19. Vue.config.mustUseProp = mustUseProp
  20. Vue.config.isReservedTag = isReservedTag
  21. Vue.config.isReservedAttr = isReservedAttr
  22. Vue.config.getTagNamespace = getTagNamespace
  23. Vue.config.isUnknownElement = isUnknownElement
  24. // install platform runtime directives & components
  25. extend(Vue.options.directives, platformDirectives)
  26. extend(Vue.options.components, platformComponents)
  27. // install platform patch function
  28. Vue.prototype.__patch__ = inBrowser ? patch : noop
  29. // public mount method
  30. Vue.prototype.$mount = function (
  31. el?: string | Element,
  32. hydrating?: boolean
  33. ): Component {
  34. el = el && inBrowser ? query(el) : undefined
  35. return mountComponent(this, el, hydrating)
  36. }
  37. // devtools global hook
  38. /* istanbul ignore next */
  39. Vue.nextTick(() => {
  40. if (config.devtools) {
  41. if (devtools) {
  42. devtools.emit('init', Vue)
  43. } else if (process.env.NODE_ENV !== 'production' && isChrome) {
  44. console[console.info ? 'info' : 'log'](
  45. 'Download the Vue Devtools extension for a better development experience:\n' +
  46. 'https://github.com/vuejs/vue-devtools'
  47. )
  48. }
  49. }
  50. if (process.env.NODE_ENV !== 'production' &&
  51. config.productionTip !== false &&
  52. inBrowser && typeof console !== 'undefined'
  53. ) {
  54. console[console.info ? 'info' : 'log'](
  55. `You are running Vue in development mode.\n` +
  56. `Make sure to turn on production mode when deploying for production.\n` +
  57. `See more tips at https://vuejs.org/guide/deployment.html`
  58. )
  59. }
  60. }, 0)
  61. export default Vue