app.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 'use strict'
  2. /* global siteConfig */
  3. import CONSTANTS from './constants'
  4. import Vue from 'vue'
  5. import VueRouter from 'vue-router'
  6. import VueClipboards from 'vue-clipboards'
  7. import VueSimpleBreakpoints from 'vue-simple-breakpoints'
  8. import VeeValidate from 'vee-validate'
  9. import { ApolloClient } from 'apollo-client'
  10. import { BatchHttpLink } from 'apollo-link-batch-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 store from './store'
  17. // ====================================
  18. // Load Modules
  19. // ====================================
  20. import boot from './modules/boot'
  21. import localization from './modules/localization'
  22. // ====================================
  23. // Load Helpers
  24. // ====================================
  25. import helpers from './helpers'
  26. // ====================================
  27. // Initialize Global Vars
  28. // ====================================
  29. window.WIKI = null
  30. window.boot = boot
  31. window.CONSTANTS = CONSTANTS
  32. window.Hammer = Hammer
  33. // ====================================
  34. // Initialize Apollo Client (GraphQL)
  35. // ====================================
  36. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + siteConfig.path + 'graphql'
  37. window.graphQL = new ApolloClient({
  38. link: new BatchHttpLink({
  39. uri: graphQLEndpoint,
  40. credentials: 'include'
  41. }),
  42. cache: new InMemoryCache(),
  43. connectToDevTools: (process.env.node_env === 'development')
  44. })
  45. // ====================================
  46. // Initialize Vue Modules
  47. // ====================================
  48. Vue.use(VueRouter)
  49. Vue.use(VueApollo)
  50. Vue.use(VueClipboards)
  51. Vue.use(VueSimpleBreakpoints)
  52. Vue.use(localization.VueI18Next)
  53. Vue.use(helpers)
  54. Vue.use(VeeValidate, {
  55. enableAutoClasses: true,
  56. classNames: {
  57. touched: 'is-touched', // the control has been blurred
  58. untouched: 'is-untouched', // the control hasn't been blurred
  59. valid: 'is-valid', // model is valid
  60. invalid: 'is-invalid', // model is invalid
  61. pristine: 'is-pristine', // control has not been interacted with
  62. dirty: 'is-dirty' // control has been interacted with
  63. }
  64. })
  65. Vue.use(Vuetify)
  66. Vue.prototype.Velocity = Velocity
  67. // ====================================
  68. // Register Vue Components
  69. // ====================================
  70. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  71. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  72. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  73. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/nav-header.vue'))
  74. Vue.component('navigator', () => import(/* webpackMode: "eager" */ './components/navigator.vue'))
  75. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  76. Vue.component('toggle', () => import(/* webpackMode: "eager" */ './components/toggle.vue'))
  77. let bootstrap = () => {
  78. // ====================================
  79. // Notifications
  80. // ====================================
  81. window.addEventListener('beforeunload', () => {
  82. store.dispatch('startLoading')
  83. })
  84. const apolloProvider = new VueApollo({
  85. defaultClient: window.graphQL
  86. })
  87. // ====================================
  88. // Bootstrap Vue
  89. // ====================================
  90. const i18n = localization.init()
  91. window.WIKI = new Vue({
  92. el: '#app',
  93. components: {},
  94. mixins: [helpers],
  95. provide: apolloProvider.provide(),
  96. store,
  97. i18n
  98. })
  99. // ----------------------------------
  100. // Dispatch boot ready
  101. // ----------------------------------
  102. window.boot.notify('vue')
  103. // ====================================
  104. // Load Icons
  105. // ====================================
  106. import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  107. document.body.insertAdjacentHTML('beforeend', icons)
  108. })
  109. }
  110. window.boot.onDOMReady(bootstrap)