File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import url from 'url'
44import path from 'path'
55import * as fs from 'fs'
6+ import { execSync } from 'child_process'
67import CopyPlugin from 'copy-webpack-plugin'
78import TerserPlugin from 'terser-webpack-plugin'
89import { 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+
2940export 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'
You can’t perform that action at this time.
0 commit comments