Skip to content

Commit b14657f

Browse files
committed
Utilize latest git tag version to manifest.
1 parent 99eb16c commit b14657f

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

webpack.config.mjs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import url from 'url'
44
import path from 'path'
55
import * as fs from 'fs'
6+
import { execSync } from 'child_process'
67
import CopyPlugin from 'copy-webpack-plugin'
78
import TerserPlugin from 'terser-webpack-plugin'
89
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
@@ -26,6 +27,16 @@ function aliases () {
2627
return aliases
2728
}
2829

30+
function latestGitTag () {
31+
let latestGitTag = '0.0.0'
32+
try {
33+
latestGitTag = execSync('git describe --tags --abbrev=0').toString().trim()
34+
} catch {
35+
console.log('\x1b[33m%s\x1b[0m', `WARNING: Could not get git tag. Defaulting to version ${latestGitTag}`)
36+
}
37+
return latestGitTag
38+
}
39+
2940
export default {
3041
mode: 'development',
3142
devtool: 'source-map',
@@ -92,7 +103,19 @@ export default {
92103
]
93104
}),
94105
new CopyPlugin({
95-
patterns: [{ from: '.', to: '.', context: 'src/assets/static' }]
106+
patterns: [{
107+
from: '.',
108+
to: '.',
109+
context: 'src/assets/static',
110+
transform: (content, absoluteFilePath) => {
111+
if (!absoluteFilePath.endsWith('manifest.json')) return content
112+
113+
const manifest = JSON.parse(content.toString())
114+
manifest.version = latestGitTag()
115+
116+
return JSON.stringify(manifest, null, 2)
117+
}
118+
}]
96119
}),
97120
new MiniCssExtractPlugin({
98121
filename: '[name].css'

0 commit comments

Comments
 (0)