Building Yeoman app breaks CSS background images

流过昼夜 提交于 2019-12-04 14:31:35

See https://github.com/yeoman/generator-angular/issues/667.

After removing the cssmin section I ran into another problem: images urls included in css files weren't being correctly revved.

I fixed that last issue by adding images path to usemin assetsDir:

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

What fixed the CSS background-image revving for me was to add a CSS pattern in options, which finds all asset references in the CSS and replaces them with the revved assets.

// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
  ...
  ...
  options: {
    ...
    ...
    // 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']
      ]
    }
  }
},
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!