app.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict'
  2. /* global siteConfig */
  3. import Vue from 'vue'
  4. import VueRouter from 'vue-router'
  5. import VueClipboards from 'vue-clipboards'
  6. import VueSimpleBreakpoints from 'vue-simple-breakpoints'
  7. import VeeValidate from 'vee-validate'
  8. import { ApolloClient } from 'apollo-client'
  9. import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
  10. // import { BatchHttpLink } from 'apollo-link-batch-http'
  11. import { createHttpLink } from 'apollo-link-http'
  12. import { InMemoryCache } from 'apollo-cache-inmemory'
  13. import VueApollo from 'vue-apollo'
  14. import Vuetify from 'vuetify'
  15. import Velocity from 'velocity-animate'
  16. import Hammer from 'hammerjs'
  17. import moment from 'moment'
  18. import VueMoment from 'vue-moment'
  19. import store from './store'
  20. // ====================================
  21. // Load Modules
  22. // ====================================
  23. import boot from './modules/boot'
  24. import localization from './modules/localization'
  25. // ====================================
  26. // Load Helpers
  27. // ====================================
  28. import helpers from './helpers'
  29. // ====================================
  30. // Initialize Global Vars
  31. // ====================================
  32. window.WIKI = null
  33. window.boot = boot
  34. window.Hammer = Hammer
  35. moment.locale(siteConfig.lang)
  36. // ====================================
  37. // Initialize Apollo Client (GraphQL)
  38. // ====================================
  39. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'
  40. const graphQLLink = createPersistedQueryLink().concat(createHttpLink({
  41. includeExtensions: true,
  42. uri: graphQLEndpoint,
  43. credentials: 'include'
  44. }))
  45. window.graphQL = new ApolloClient({
  46. link: graphQLLink,
  47. cache: new InMemoryCache(),
  48. connectToDevTools: (process.env.node_env === 'development')
  49. })
  50. // ====================================
  51. // Initialize Vue Modules
  52. // ====================================
  53. Vue.config.productionTip = false
  54. Vue.use(VueRouter)
  55. Vue.use(VueApollo)
  56. Vue.use(VueClipboards)
  57. Vue.use(VueSimpleBreakpoints)
  58. Vue.use(localization.VueI18Next)
  59. Vue.use(helpers)
  60. Vue.use(VeeValidate, { events: '' })
  61. Vue.use(Vuetify)
  62. Vue.use(VueMoment, { moment })
  63. Vue.prototype.Velocity = Velocity
  64. // ====================================
  65. // Register Vue Components
  66. // ====================================
  67. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  68. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  69. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  70. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/nav-header.vue'))
  71. Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
  72. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  73. Vue.component('v-card-chin', () => import(/* webpackMode: "eager" */ './components/common/v-card-chin.vue'))
  74. let bootstrap = () => {
  75. // ====================================
  76. // Notifications
  77. // ====================================
  78. window.addEventListener('beforeunload', () => {
  79. store.dispatch('startLoading')
  80. })
  81. const apolloProvider = new VueApollo({
  82. defaultClient: window.graphQL
  83. })
  84. // ====================================
  85. // Bootstrap Vue
  86. // ====================================
  87. const i18n = localization.init()
  88. window.WIKI = new Vue({
  89. el: '#app',
  90. components: {},
  91. mixins: [helpers],
  92. provide: apolloProvider.provide(),
  93. store,
  94. i18n
  95. })
  96. // ----------------------------------
  97. // Dispatch boot ready
  98. // ----------------------------------
  99. window.boot.notify('vue')
  100. // ====================================
  101. // Load Icons
  102. // ====================================
  103. import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  104. document.body.insertAdjacentHTML('beforeend', icons.default)
  105. })
  106. }
  107. window.boot.onDOMReady(bootstrap)