app.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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(
  41. createHttpLink({
  42. includeExtensions: true,
  43. uri: graphQLEndpoint,
  44. credentials: 'include',
  45. fetch: (uri, options) => {
  46. // Strip __typename fields from variables
  47. let body = JSON.parse(options.body)
  48. // body = body.map(bd => {
  49. // return ({
  50. // ...bd,
  51. // variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })
  52. // })
  53. // })
  54. body = {
  55. ...body,
  56. variables: JSON.parse(JSON.stringify(body.variables), (key, value) => { return key === '__typename' ? undefined : value })
  57. }
  58. options.body = JSON.stringify(body)
  59. // Inject authentication token
  60. options.headers.Authorization = `Bearer TODO`
  61. return fetch(uri, options)
  62. }
  63. })
  64. )
  65. window.graphQL = new ApolloClient({
  66. link: graphQLLink,
  67. cache: new InMemoryCache(),
  68. connectToDevTools: (process.env.node_env === 'development')
  69. })
  70. // ====================================
  71. // Initialize Vue Modules
  72. // ====================================
  73. Vue.config.productionTip = false
  74. Vue.use(VueRouter)
  75. Vue.use(VueApollo)
  76. Vue.use(VueClipboards)
  77. Vue.use(VueSimpleBreakpoints)
  78. Vue.use(localization.VueI18Next)
  79. Vue.use(helpers)
  80. Vue.use(VeeValidate, { events: '' })
  81. Vue.use(Vuetify)
  82. Vue.use(VueMoment, { moment })
  83. Vue.prototype.Velocity = Velocity
  84. // ====================================
  85. // Register Vue Components
  86. // ====================================
  87. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  88. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  89. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  90. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/nav-header.vue'))
  91. Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
  92. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  93. Vue.component('v-card-chin', () => import(/* webpackMode: "eager" */ './components/common/v-card-chin.vue'))
  94. let bootstrap = () => {
  95. // ====================================
  96. // Notifications
  97. // ====================================
  98. window.addEventListener('beforeunload', () => {
  99. store.dispatch('startLoading')
  100. })
  101. const apolloProvider = new VueApollo({
  102. defaultClient: window.graphQL
  103. })
  104. // ====================================
  105. // Bootstrap Vue
  106. // ====================================
  107. const i18n = localization.init()
  108. window.WIKI = new Vue({
  109. el: '#app',
  110. components: {},
  111. mixins: [helpers],
  112. provide: apolloProvider.provide(),
  113. store,
  114. i18n
  115. })
  116. // ----------------------------------
  117. // Dispatch boot ready
  118. // ----------------------------------
  119. window.boot.notify('vue')
  120. // ====================================
  121. // Load Icons
  122. // ====================================
  123. import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  124. document.body.insertAdjacentHTML('beforeend', icons.default)
  125. })
  126. }
  127. window.boot.onDOMReady(bootstrap)