我正在使用react/es6/webpack。我想在應用程序中的某處顯示構建日期和git散列。什麼是最好的方法?在webpack中包含git commit hash和date
15
A
回答
25
可以使用的WebPack的DefinePlugin
https://webpack.github.io/docs/list-of-plugins.html#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),
})
]
...
然後你就可以用__COMMIT_HASH__
4
在您的應用程序中使用它這樣做的另一種方法是:
只要安裝這個包git-revision-webpack-plugin
簡單的webpack插件,基於本地git存儲庫生成VERSION和COMMITHASH文件 。
示例代碼:
您webpack.config.js內(或任何開發 - 督促文件)
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin();
plugins: [
new DefinePlugin({
'VERSION': JSON.stringify(gitRevisionPlugin.version()),
'COMMITHASH': JSON.stringify(gitRevisionPlugin.commithash()),
'BRANCH': JSON.stringify(gitRevisionPlugin.branch()),
}),
]
在組件(反應):
export class Home extends Component{
....
render() {
return(
<div>
{VERSION}
{COMMITHASH}
{BRANCH}
</div>
)
}
}
在您的模板(角度)中:
{{ VERSION }}
{{ COMMITHASH }}
{{ BRANCH }}
相關問題
- 1. 在jar版本中包含git commit hash
- 2. Git commit date
- 3. 在git commit消息中包含日期或其他變量
- 4. 如何在Eclipse中記錄最新的git commit hash?
- 5. 包含:'date'.php
- 6. 在Play 2 Framework中,如何在sbt dist包名中包含git commit sha?
- 7. 如何在包含babel,Node.js和webpack的項目中包含jQuery?
- 8. 如何從VS/msbuild中提取Git commit hash?
- 9. SLOC在git commit
- 10. 在webpack中包含第三方庫
- 11. Git:爲緩存破壞目的檢索short commit hash
- 12. 「git reset --hard hash」和「git checkout hash」有區別嗎?
- 13. Git Bash和webpack
- 14. 在提交後將git commit hash添加到粘貼緩衝區中
- 15. git-svn dmitmiting git commit
- 16. git commit error:name只包含不允許的字符:
- 17. ^在Git commit消息中的M個字符(git commit -v)
- 18. 在webpack中包含外部庫
- 19. 如何在Webpack中包含jQuery CDN?
- 20. 使用git commit -a和vim
- 21. 什麼做「git checkout \ *」和「git commit - 」完成?
- 22. git find fat commit
- 23. git commit directory
- 24. Aptana 3 git commit
- 25. 刪除git commit
- 26. Git commit bash腳本
- 27. Git post commit mails
- 28. git commit problems
- 29. git commit - 格式?
- 30. Git commit命令