Gruntjs 无法用grunt usemin';替换HTML基标记;s自定义块替换

Gruntjs 无法用grunt usemin';替换HTML基标记;s自定义块替换,gruntjs,grunt-usemin,angular-fullstack,Gruntjs,Grunt Usemin,Angular Fullstack,我试图用/mydir/替换HTML基标记的href属性值。已经尝试使用grunt usemin的blockReplacements来实现这一点 这里是配置 // Reads HTML for usemin blocks to enable smart builds that automatically // concat, minify and revision files. Creates configurations in memory so // additional tasks can

我试图用/mydir/替换HTML基标记的href属性值。已经尝试使用grunt usemin的blockReplacements来实现这一点

这里是配置

// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
  html: ['<%= yeoman.client %>/index.html'],
  options: {
    dest: '<%= yeoman.dist %>/public'
  }
},

// Performs rewrites based on rev and the useminPrepare configuration
usemin: {

  html: ['<%= yeoman.dist %>/public/{,*/}*.html'],
  css: ['<%= yeoman.dist %>/public/{,*/}*.css'],
  js: ['<%= yeoman.dist %>/public/{,*/}*.js'],
  options: {
    assetsDirs: [
      '<%= yeoman.dist %>/public',
      '<%= yeoman.dist %>/public/assets/images'
    ],
    blockReplacements: {
      baseUrl: function (block) {
        grunt.log.debug("******************* blockReplacements *******************");
        return '<base href="/mydir/">';
      }
    },

    // This is so we update image references in our ng-templates
    patterns: {
      js: [
        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
      ]
    }

  }
}
但这只是删除了基本标记,而不是替换。 我怀疑我需要在Gruntfile中配置一个baseUrl属性,但我并没有试图修改/uglify文件,我相信这个属性会指向需要修改的文件等

此外,我还尝试运行调试来激发grunt.log.debug调用buildReplace函数:

$ grunt --debug serve:dist
但是没有控制台输出

注意:我的应用程序基于角度全堆栈生成器应用程序。

欢迎提供任何帮助或建议。

您必须使用以下命令:
grunt构建

在没有任何进展之后,我已经有一段时间没有再讨论这个问题了。刚刚重温,它似乎从grunt usemin升级为“~2.1.1”到grunt usemin:“3.0.0”解决了这个问题。仍然不确定3.0.0中是否存在修复此问题的特定错误地址

另请注意:GrunFile中的baseUrl分配了一个函数,第一个参数为block:

baseUrl: function (block) {
    grunt.log.debug("******************* blockReplacements *******************");
    return '<base href="/mydir/">';
}
baseUrl:函数(块){
grunt.log.debug(“*************************块替换*************************”);
返回“”;
}
这个名为block的参数实际上并没有在函数中使用,href返回是一个字符串(我知道这很糟糕,不应该这样使用,但只是在这里指出了一些东西)。在client/index.html中对此函数的调用必须传递一个参数:

<!-- build:baseUrl /mydir/ -->
<base href="/">
<!-- endbuild -->

如果去掉/mydir/url部分,以下内容将无法创建基本标记:

<!-- build:baseUrl -->
<base href="/">
<!-- endbuild -->


因此,实际上我们可以添加一些垃圾url部分,它不会失败,也不会对基本标记的结果产生任何影响。

它不是
base
而不是
baseUrl
<!-- build:baseUrl /mydir/ -->
<base href="/">
<!-- endbuild -->
<!-- build:baseUrl -->
<base href="/">
<!-- endbuild -->