app.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 VueTour from 'vue-tour'
  20. import VueTreeNavigation from 'vue-tree-navigation'
  21. import store from './store'
  22. // ====================================
  23. // Load Modules
  24. // ====================================
  25. import boot from './modules/boot'
  26. import localization from './modules/localization'
  27. // ====================================
  28. // Load Helpers
  29. // ====================================
  30. import helpers from './helpers'
  31. // ====================================
  32. // Initialize Global Vars
  33. // ====================================
  34. window.WIKI = null
  35. window.boot = boot
  36. window.Hammer = Hammer
  37. moment.locale(siteConfig.lang)
  38. // ====================================
  39. // Initialize Apollo Client (GraphQL)
  40. // ====================================
  41. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'
  42. const graphQLLink = createPersistedQueryLink().concat(
  43. createHttpLink({
  44. includeExtensions: true,
  45. uri: graphQLEndpoint,
  46. credentials: 'include',
  47. fetch: (uri, options) => {
  48. // Strip __typename fields from variables
  49. let body = JSON.parse(options.body)
  50. // body = body.map(bd => {
  51. // return ({
  52. // ...bd,
  53. // variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })
  54. // })
  55. // })
  56. body = {
  57. ...body,
  58. variables: JSON.parse(JSON.stringify(body.variables), (key, value) => { return key === '__typename' ? undefined : value })
  59. }
  60. options.body = JSON.stringify(body)
  61. // Inject authentication token
  62. options.headers.Authorization = `Bearer TODO`
  63. return fetch(uri, options)
  64. }
  65. })
  66. )
  67. window.graphQL = new ApolloClient({
  68. link: graphQLLink,
  69. cache: new InMemoryCache(),
  70. connectToDevTools: (process.env.node_env === 'development')
  71. })
  72. // ====================================
  73. // Initialize Vue Modules
  74. // ====================================
  75. Vue.config.productionTip = false
  76. Vue.use(VueRouter)
  77. Vue.use(VueApollo)
  78. Vue.use(VueClipboards)
  79. Vue.use(VueSimpleBreakpoints)
  80. Vue.use(localization.VueI18Next)
  81. Vue.use(helpers)
  82. Vue.use(VeeValidate, { events: '' })
  83. Vue.use(Vuetify)
  84. Vue.use(VueMoment, { moment })
  85. Vue.use(VueTour)
  86. Vue.use(VueTreeNavigation)
  87. Vue.prototype.Velocity = Velocity
  88. // ====================================
  89. // Register Vue Components
  90. // ====================================
  91. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  92. Vue.component('editor', () => import(/* webpackPrefetch: -100, webpackChunkName: "editor" */ './components/editor.vue'))
  93. Vue.component('login', () => import(/* webpackPrefetch: true, webpackChunkName: "login" */ './components/login.vue'))
  94. Vue.component('nav-footer', () => import(/* webpackMode: "eager" */ './components/common/nav-footer.vue'))
  95. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/common/nav-header.vue'))
  96. Vue.component('nav-sidebar', () => import(/* webpackMode: "eager" */ './components/common/nav-sidebar.vue'))
  97. Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
  98. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  99. Vue.component('v-card-chin', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/v-card-chin.vue'))
  100. Vue.component('page', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/app.vue'))
  101. let bootstrap = () => {
  102. // ====================================
  103. // Notifications
  104. // ====================================
  105. window.addEventListener('beforeunload', () => {
  106. store.dispatch('startLoading')
  107. })
  108. const apolloProvider = new VueApollo({
  109. defaultClient: window.graphQL
  110. })
  111. // ====================================
  112. // Bootstrap Vue
  113. // ====================================
  114. const i18n = localization.init()
  115. window.WIKI = new Vue({
  116. el: '#root',
  117. components: {},
  118. mixins: [helpers],
  119. provide: apolloProvider.provide(),
  120. store,
  121. i18n
  122. })
  123. // ----------------------------------
  124. // Dispatch boot ready
  125. // ----------------------------------
  126. window.boot.notify('vue')
  127. // ====================================
  128. // Load Icons
  129. // ====================================
  130. // import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  131. // document.body.insertAdjacentHTML('beforeend', icons.default)
  132. // })
  133. }
  134. window.boot.onDOMReady(bootstrap)