【问题标题】:grunt task svgmin removes id from symbol taggrunt task svgmin 从符号标签中删除 id
【发布时间】:2014-10-10 02:55:09
【问题描述】:

我在我的 sag 文件中使用带有 id 的符号标签,如以下链接中所述: http://css-tricks.com/svg-symbol-good-choice-icons/

使用 grunt task svgmin 放大后,我的所有 id 都会从我的 svg 文件中删除。

我的咕噜任务如下:

svgmin: {
    options: {
      plugins: [
        { removeViewBox: false},
        { removeUselessStrokeAndFill: false}, 
        { removeEmptyAttrs: false }
      ]
    },

  dist: {
    files: [{
      expand: true,
      cwd: '<%= yeoman.app %>/images',
      src: '{,*/}*.svg',
      dest: '<%= yeoman.dist %>/images'
    }]
  }
},

有没有办法解决这个问题?

【问题讨论】:

    标签: svg gruntjs


    【解决方案1】:

    以下内容对我有用。

    svgmin: {
          options: {
            full: true,
            plugins: [
              {cleanupIDs: false},                  // don't remove  ids
              {removeViewBox: false},               // don't remove the viewbox atribute from the SVG
              {removeUselessStrokeAndFill: false},  // don't remove Useless Strokes and Fills
              {removeEmptyAttrs: false}             // don't remove Empty Attributes from the SVG
            ]
          },
          dist: {
            files: [{
              expand: true,
              cwd: '<%= yeoman.app %>/images',
              src: '{,*/}*.svg',
              dest: '<%= yeoman.dist %>/images'
            }]
          }
        }
    

    {cleanupIDs: false} 不能像 here 报告的那样工作。解决方案是添加 full:true ,如上述示例所示。我正在使用 "grunt-svgmin": "^0.4.0" 进行测试。

    【讨论】:

      【解决方案2】:

      您需要将 cleanupIDs 插件设置为 false,因为它默认设置为 true。只需在您的 removeEmptyAttrs 行之后添加:

      { cleanupIDs: false }

      不要忘记前一个花括号后面的逗号 :)

      这里是您可以禁用/启用的 SVGO 插件的完整列表:https://github.com/svg/svgo/tree/master/plugins

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-27
        • 2015-09-07
        相关资源
        最近更新 更多