【问题标题】:Grunt-usemin doesn't update reference to html templateGrunt-usemin 不更新对 html 模板的引用
【发布时间】:2015-04-30 22:23:43
【问题描述】:

我正在尝试使用 usemin 模式更新 js 文件中的模板 url,以防止版本更改时出现缓存错误。

当我将filerev 更改为关注时,它会重命名所有模板,这正是我想要的。

 filerev: {
      dist: {
        src: [
          '<%= yeoman.dist %>/scripts/**/*.js',
          '<%= yeoman.dist %>/styles/**/*.css',
          '<%= yeoman.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
          '<%= yeoman.dist %>/styles/fonts/*',
          '<%= yeoman.dist %>/views/**/*.html'
        ]
      }
    },

但即使我尝试为此配置usemin,我也无法更新网址。

usemin: {
      html: ['<%= yeoman.dist %>/**/*.html'],
      css: ['<%= yeoman.dist %>/styles/**/*.css'],
      options: {
        assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images'],
        patterns:{
          js:[
              [/(views\/.*?\.(html))/gm, 'Update template urls in the js files']
          ]
        }
      }
    },

【问题讨论】:

  • 你找到答案了吗?我也有同样的问题。
  • 很遗憾,没有,我使用了一种解决方法。我使用 http 拦截器在 Angular 上设置了特定于版本的查询参数。基本上它在每个请求“?version = 313jkf1f”的url中添加了一个这样的参数。我不知道这是否理想,但它会阻止缓存新版本。

标签: angularjs gruntjs grunt-usemin


【解决方案1】:

我尝试了类似的配置,但它根本不起作用。

usemin: {
  html: ['<%= yeoman.dist %>/**/*.html'],
  css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  js: ['<%= yeoman.dist %>/scripts/*.js'],
  options: {
    assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/assets'],
    patterns: {
      js: [
        [/(views\/.*?\.(html))/gm, 'Update template urls in the js files']
      ]
    }
  }
}

请注意我添加了:

js: ['<%= yeoman.dist %>/scripts/*.js']

然后我意识到useminrequirejs:dist 之后触发,在我的例子中创建main.js,合并和缩小。希望有人也错过了:)

【讨论】:

    猜你喜欢
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多