【问题标题】:How to hook to webpack-dev-server build?如何挂钩到 webpack-dev-server 构建?
【发布时间】:2015-11-24 10:37:13
【问题描述】:

我正在使用 webpack 和 webpack-dev-server。

我想在我的 html 页面上显示 git describe 输出。

有没有办法hook webpack-dev-server 重建,执行git describe,然后把输出放到页面的某处?

【问题讨论】:

    标签: git webpack webpack-dev-server


    【解决方案1】:

    我的解决方案:我为 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');
      });
    };
    

    【讨论】:

    【解决方案2】:

    如果您是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');
    });
    

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 2020-08-26
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 2018-01-06
      • 2019-11-09
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多