Add commit hash into vite build
This commit is contained in:
parent
eb6d9cdd4b
commit
baad129b49
3 changed files with 21 additions and 2 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
|
@ -1 +1 @@
|
||||||
/build/webpack.prod.conf.js export-subst
|
/build/commit_hash.js export-subst
|
||||||
|
|
|
||||||
18
build/commit_hash.js
Normal file
18
build/commit_hash.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import childProcess from 'child_process'
|
||||||
|
|
||||||
|
export const getCommitHash = (() => {
|
||||||
|
const subst = "$Format:%h$"
|
||||||
|
if(!subst.match(/Format:/)) {
|
||||||
|
return subst
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return childProcess
|
||||||
|
.execSync('git rev-parse --short HEAD')
|
||||||
|
.toString()
|
||||||
|
.trim()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed run git:', e)
|
||||||
|
return 'UNKNOWN'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -7,6 +7,7 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||||
import { VitePWA } from 'vite-plugin-pwa'
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
import { devSwPlugin, buildSwPlugin, swMessagesPlugin } from './build/sw_plugin.js'
|
import { devSwPlugin, buildSwPlugin, swMessagesPlugin } from './build/sw_plugin.js'
|
||||||
import copyPlugin from './build/copy_plugin.js'
|
import copyPlugin from './build/copy_plugin.js'
|
||||||
|
import { getCommitHash } from './build/commit_hash.js'
|
||||||
|
|
||||||
const localConfigPath = '<projectRoot>/config/local.json'
|
const localConfigPath = '<projectRoot>/config/local.json'
|
||||||
const getLocalDevSettings = async () => {
|
const getLocalDevSettings = async () => {
|
||||||
|
|
@ -116,7 +117,7 @@ export default defineConfig(async ({ mode, command }) => {
|
||||||
NODE_ENV: command === 'serve' ? 'development' : 'production',
|
NODE_ENV: command === 'serve' ? 'development' : 'production',
|
||||||
HAS_MODULE_SERVICE_WORKER: command === 'serve' && !transformSW
|
HAS_MODULE_SERVICE_WORKER: command === 'serve' && !transformSW
|
||||||
}),
|
}),
|
||||||
'COMMIT_HASH': JSON.stringify('DEV'),
|
'COMMIT_HASH': JSON.stringify(command === 'serve' ? 'DEV' : getCommitHash()),
|
||||||
'DEV_OVERRIDES': JSON.stringify({})
|
'DEV_OVERRIDES': JSON.stringify({})
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue