You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.0 KiB

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