aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vuepress/lib/app/clientEntry.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vuepress/lib/app/clientEntry.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vuepress/lib/app/clientEntry.js')
-rw-r--r--node_modules/vuepress/lib/app/clientEntry.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/node_modules/vuepress/lib/app/clientEntry.js b/node_modules/vuepress/lib/app/clientEntry.js
new file mode 100644
index 00000000..dc86314a
--- /dev/null
+++ b/node_modules/vuepress/lib/app/clientEntry.js
@@ -0,0 +1,74 @@
+/* global BASE_URL, GA_ID, ga, SW_ENABLED, VUEPRESS_VERSION, LAST_COMMIT_HASH*/
+
+import { createApp } from './app'
+import SWUpdateEvent from './SWUpdateEvent'
+import { register } from 'register-service-worker'
+
+const { app, router } = createApp()
+
+window.__VUEPRESS_VERSION__ = {
+ version: VUEPRESS_VERSION,
+ hash: LAST_COMMIT_HASH
+}
+
+// Google analytics integration
+if (process.env.NODE_ENV === 'production' && GA_ID) {
+ (function (i, s, o, g, r, a, m) {
+ i['GoogleAnalyticsObject'] = r
+ i[r] = i[r] || function () {
+ (i[r].q = i[r].q || []).push(arguments)
+ }
+ i[r].l = 1 * new Date()
+ a = s.createElement(o)
+ m = s.getElementsByTagName(o)[0]
+ a.async = 1
+ a.src = g
+ m.parentNode.insertBefore(a, m)
+ })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
+
+ ga('create', GA_ID, 'auto')
+ ga('send', 'pageview')
+
+ router.afterEach(function (to) {
+ ga('set', 'page', app.$withBase(to.fullPath))
+ ga('send', 'pageview')
+ })
+}
+
+router.onReady(() => {
+ app.$mount('#app')
+
+ // Register service worker
+ if (process.env.NODE_ENV === 'production' &&
+ SW_ENABLED &&
+ window.location.protocol === 'https:') {
+ register(`${BASE_URL}service-worker.js`, {
+ ready () {
+ console.log('[vuepress:sw] Service worker is active.')
+ app.$refs.layout.$emit('sw-ready')
+ },
+ cached (registration) {
+ console.log('[vuepress:sw] Content has been cached for offline use.')
+ app.$refs.layout.$emit('sw-cached', new SWUpdateEvent(registration))
+ },
+ updated (registration) {
+ console.log('[vuepress:sw] Content updated.')
+ app.$refs.layout.$emit('sw-updated', new SWUpdateEvent(registration))
+ },
+ offline () {
+ console.log('[vuepress:sw] No internet connection found. App is running in offline mode.')
+ app.$refs.layout.$emit('sw-offline')
+ },
+ error (err) {
+ console.error('[vuepress:sw] Error during service worker registration:', err)
+ app.$refs.layout.$emit('sw-error', err)
+ if (GA_ID) {
+ ga('send', 'exception', {
+ exDescription: err.message,
+ exFatal: false
+ })
+ }
+ }
+ })
+ }
+})