Including git commit hash and date in webpack build

前端 未结 3 878
半阙折子戏
半阙折子戏 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条回答
  •  执笔经年
    2021-02-01 02:02

    I couldn't comment to the top post, so here goes:

    Webpack.dev.js

    import gitprocess from "child_process"
    let LoadCommitDate = gitprocess
      .execSync('git log -1 --date=format:"%Y/%m/%d %T" --format="%ad"')
      .toString()
    ...
    plugins: [
        new webpack.DefinePlugin({
           COMMITDATE: JSON.stringify(LoadCommitDate),
        })
      ]
    

    Additionally in .eslintrc

      "globals": {
        "COMMITDATE": "readonly",
      },
    

    Result - latest commit date you can reference in your code!

    console.log(COMMITDATE)
    2020/05/04 21:02:03
    

提交回复
热议问题