Skip to content

Commit

Permalink
fix(vue.config): should work without git log, close #23
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed May 5, 2020
1 parent 87d130e commit faf6c8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ export default {
href: `https://github.com/lbwa/vue-auth-boilerplate/releases/v${__VERSION__}`
},
commit: {
label: __COMMIT_HASH__.slice(0, 15),
href: `https://github.com/lbwa/vue-auth-boilerplate/commit/${__COMMIT_HASH__}`
label: __COMMIT_HASH__
? __COMMIT_HASH__.slice(0, 15)
: 'Not a git repository',
href: __COMMIT_HASH__
? `https://github.com/lbwa/vue-auth-boilerplate/commit/${__COMMIT_HASH__}`
: ''
},
latestBuild: new Date(__BUILD_TIME__).toLocaleString()
})
Expand Down
17 changes: 11 additions & 6 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ module.exports = {

chainWebpack(config) {
/**
* Feature flags
* Feature flags in **compiler** time
* @doc https://webpack.js.org/plugins/define-plugin/#feature-flags
*/
config.plugin('define').tap(([args]) => {
args.__DEV__ = JSON.stringify(__DEV__)
args.__BUILD_TIME__ = JSON.stringify(new Date().toString())
args.__VERSION__ = JSON.stringify(require('./package.json').version)
args.__COMMIT_HASH__ = JSON.stringify(
require('child_process')
.execSync('git rev-parse HEAD')
.toString()
)
try {
args.__COMMIT_HASH__ = JSON.stringify(
require('child_process')
.execSync('git rev-parse HEAD')
.toString()
)
} catch (err) {
// works without git
args.__COMMIT_HASH__ = JSON.stringify('')
}
return [args]
})

Expand Down

0 comments on commit faf6c8c

Please sign in to comment.