diff --git a/lib/app/clientEntry.js b/lib/app/clientEntry.js index 4b11dbb48b..5691528ebf 100644 --- a/lib/app/clientEntry.js +++ b/lib/app/clientEntry.js @@ -1,10 +1,15 @@ -/* global BASE_URL, GA_ID, ga, SW_ENABLED */ +/* global BASE_URL, GA_ID, ga, SW_ENABLED, VUEPRESS_VERSION, LAST_COMMIT_HASH*/ import { createApp } from './app' 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) { diff --git a/lib/webpack/createBaseConfig.js b/lib/webpack/createBaseConfig.js index 428344cb78..cee40f856a 100644 --- a/lib/webpack/createBaseConfig.js +++ b/lib/webpack/createBaseConfig.js @@ -291,8 +291,19 @@ module.exports = function createBaseConfig ({ .use(require('webpack/lib/DefinePlugin'), [{ BASE_URL: JSON.stringify(siteConfig.base || '/'), GA_ID: siteConfig.ga ? JSON.stringify(siteConfig.ga) : false, - SW_ENABLED: !!siteConfig.serviceWorker + SW_ENABLED: !!siteConfig.serviceWorker, + VUEPRESS_VERSION: JSON.stringify(require('../../package.json').version), + LAST_COMMIT_HASH: JSON.stringify(getLastCommitHash()) }]) return config } + +function getLastCommitHash () { + const spawn = require('cross-spawn') + let hash + try { + hash = spawn.sync('git', ['log', '-1', '--format=%h']).stdout.toString('utf-8').trim() + } catch (error) {} + return hash +}