Including git commit hash and date in webpack build

前端 未结 3 1002
半阙折子戏
半阙折子戏 2021-02-01 01:04

I\'m using react/es6/webpack. I want to show the date of the build and git hash somewhere in my app. What\'s the best approach?

3条回答
  •  旧时难觅i
    2021-02-01 01:39

    You can use webpack's DefinePlugin:

    // get git info from command line
    let commitHash = require('child_process')
      .execSync('git rev-parse --short HEAD')
      .toString();
    
    ...
    plugins: [
        new webpack.DefinePlugin({
          __COMMIT_HASH__: JSON.stringify(commitHash),
        })
      ]
    ...
    

    Then you can use it in your app with __COMMIT_HASH__

提交回复
热议问题