我正在使用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 hash作为字符串包含在Rust程序中
- 3. Git commit date
- 4. 用git hash-object构建git commit对象?
- 5. 是一个git commit hash可信吗?
- 6. 在git commit消息中包含日期或其他变量
- 7. 在Visual Studio中将git commit hash设置为dll版本号
- 8. 如何在Eclipse中记录最新的git commit hash?
- 9. 包含:'date'.php
- 10. git commit中断时区
- 11. 在Play 2 Framework中,如何在sbt dist包名中包含git commit sha?
- 12. 如何在包含babel,Node.js和webpack的项目中包含jQuery?
- 13. 如何从VS/msbuild中提取Git commit hash?
- 14. git commit integrity
- 15. 结合git add。和git commit
- 16. git commit -m vs git commit -am
- 17. GitHub:找出一个版本中是否包含git commit?
- 18. 在webpack中包含第三方库
- 19. SLOC在git commit
- 20. (git add -A后跟git commit)和git commit -a之间的区别?
- 21. Git Bash和webpack
- 22. Jenkins:将git commit hash传递给下游作业
- 23. 从git commit hash获取文件或文件夹
- 24. Git:为缓存破坏目的检索short commit hash
- 25. “git reset --hard hash”和“git checkout hash”有区别吗?
- 26. 不能在包含JSpack的JS库中包含Angular2中的Webpack
- 27. 在Git commit summary中标记?
- 28. 在提交后将git commit hash添加到粘贴缓冲区中
- 29. webpack [hash]和[chunkhash]的用途是什么?
- 30. git-svn dmitmiting git commit