svg - 使用 gulp-svg-sprite 生成 SASS mixin?

标签 svg gulp sprite

我正在使用 gulp-svg-sprite 插件。

https://github.com/jkphl/gulp-svg-sprite

https://github.com/jkphl/svg-sprite

我已经有了我想要 Sprite 的类和样式:

    .header {
      background: grey;

      &:after {
        content: "";
        display: block;
        height: 30px;
        width: 30px;
        background: url(images/icon1.svg);
      }
    }

这是我的任务:

    spriteConfig    = {
      mode          : {
        css        : {
          bust      : true,
          render    : {
            scss    : true
          }
        }
      }
    };

    gulp.task('sprite', function() {
      gulp.src('images/svg/*.svg')
        .pipe(svgSprite(spriteConfig))
        .pipe(gulp.dest('dest/'));
    });

任务生成这种类型的 SASS:

    %svg-common {
        background: url("svg/sprite.css-c3700f6a.svg") no-repeat;
    }

    .svg-icon1 {
        @extend %svg-common;
        background-position: 50% 0;
    }

    .svg-icon1-dims {
        width: 1024px;
        height: 348px;
    }

这并不理想,因为我需要导入这些我不会自己使用的 svg- 类,然后我需要使用 2 个扩展:

    .header {
      background: grey;

      &:after {
        content: "";
        display: block;
        @extend .svg-icon1;
        @extend .svg-icon1-dims;
      }
    }

有没有一种方法可以生成 mixin,这样我就可以得到类似的东西:

    .header {
      background: grey;

      &:after {
        content: "";
        display: block;
        @include svg-icon1;
      }
    }

最佳答案

根据 docs :

It comes with a set of Mustache templates for creating stylesheets in good ol' CSS or one of the major pre-processor formats (Sass, Less and Stylus). Tweaking the templates or even adding your own custom output format is really easy, just as switching on the generation of an HTML example document along with your sprite.

查看并自定义以下文件:

https://github.com/jkphl/svg-sprite/blob/master/tmpl/css/sprite.scss

关于svg - 使用 gulp-svg-sprite 生成 SASS mixin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36748242/

相关文章:

javascript - D3.JS Y轴标签问题

javascript - D3js 移动嵌套组

javascript - Gulp watch 不触发

java - 如何在 FitViewport View 中绘制 Sprite 。 libgdx

python - Pygame 错误参数必须是 pygame.surface 而不是 None

javascript - 修复了 Highcharts 系列数据标签中的数据标签尺寸

html - SVG 图标在调整大小时未正确呈现

gulp - Browserify - 解析错误 : 'import' and 'export' may appear only with 'sourceType: module

javascript - gulp services 命令后超时

objective-c - SpriteKit - SKSpriteNode physicsBody 未形成 CGPath