【发布时间】:2015-11-24 10:37:13
【问题描述】:
我正在使用 webpack 和 webpack-dev-server。
我想在我的 html 页面上显示 git describe 输出。
有没有办法hook webpack-dev-server 重建,执行git describe,然后把输出放到页面的某处?
【问题讨论】:
标签: git webpack webpack-dev-server
我正在使用 webpack 和 webpack-dev-server。
我想在我的 html 页面上显示 git describe 输出。
有没有办法hook webpack-dev-server 重建,执行git describe,然后把输出放到页面的某处?
【问题讨论】:
标签: git webpack webpack-dev-server
我的解决方案:我为 webpack 编写了插件
var GitDescribePlugin = function(/*options*/) {
};
GitDescribePlugin.prototype.apply = function(compiler) {
compiler.plugin("compile", function(/*params*/) {
console.log("The compiler is starting to compile...");
child_process.execSync('git describe --always > gitdescribe.txt');
});
};
【讨论】:
如果您是using webpack with grunt,则可以包含grunt-git-describe npm package。
这将允许您包含 "git-describe" task 和/或保存其输出:
grunt.registerTask('saveRevision', function() {
grunt.event.once('git-describe', function (rev) {
grunt.log.writeln("Git Revision: " + rev);
grunt.option('gitRevision', rev);
});
grunt.task.run('git-describe');
});
【讨论】: