Şu anda tepki/es6/webpack kullanıyorum. Yapımın tarihini ve uygulamasındaki bir yere git hash'ını göstermek istiyorum. En iyi yaklaşım nedir? Sen kullanabilirsinizGit commit hash ve tarih dahil webpack build
15
A
cevap
25
webpack en 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),
})
]
...
Sonra __COMMIT_HASH__
4
ile uygulamanızda kullanabilirsiniz Bunu yapmanın bir yolu:
Sadece bu paketi yüklemek git-revision-webpack-plugin
Yerel bir git deposuna dayalı olarak, oluşturma sırasında VERSION ve COMMITHASH dosyalarını oluşturan basit web paketi eklentisi.
Örnek Kod:
sizin webpack.config.js İçinde (veya herhangi bir dev - prod dosyası) Bileşen (Tepki) sizin de
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>
)
}
}
olarak Şablon olarak
(Açısal):
{{ VERSION }}
{{ COMMITHASH }}
{{ BRANCH }}