阻止grunt更改字体

时间:2015-10-08 14:39:18

标签: gruntjs yeoman grunt-usemin

所以我正处于向Yeoman项目添加字体的情况。然而,有一个小问题。每当我运行grunt build时,我的字体的文件名都会改变,但在CSS中它不会改变,导致它不起作用。

我该如何解决这个问题。我知道我必须查看Gruntfile.js内部,但我不知道在哪里看。

我已经尝试过了:

// 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',
      '<%= yeoman.dist %>/public/assets/fonts'
    ],
    // 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']
      ],
      css: [
        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the CSS to reference our revved images']
      ]
    }
  }
},

因为我认为如果我可以在CSS中更改名称,那么它可能会起作用。但这并没有真正解决任何问题: - (

更新

这里要求的是文件名中的更改

在:

ITCEDSCR.TTF

20118b60.ITCEDSCR.TTF

2 个答案:

答案 0 :(得分:1)

根据https://github.com/yeoman/generator-webapp/issues/459 - &gt;

{
usemin: {
  options: {
    assetsDirs: [
      '<%%= config.dist %>',
      '<%%= config.dist %>/images',
      '<%%= config.dist %>/styles'
    ]
  },
  html: ['<%%= config.dist %>/{,*/}*.html'],
  css: ['<%%= config.dist %>/styles/{,*/}*.css']
}
}

摆脱字体应该对我有帮助吗?

答案 1 :(得分:1)

实际解决方案!

感谢Fer To的链接我找到了解决方案。这有点像他的建议,只需要在其他地方更改代码。

这是我的解决方案:

// Renames files for browser caching purposes
rev: {
  dist: {
    files: {
      src: [
        '<%= yeoman.dist %>/public/{,*/}*.js',
        '<%= yeoman.dist %>/public/{,*/}*.css',
        //'<%= yeoman.dist %>/public/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
        //'<%= yeoman.dist %>/public/assets/fonts/*'
      ]
    }
  }
},

// 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'
    ],
    // 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']
      ]
    }
  }
},