【问题标题】:Exclude SVG from gulp-svg-sprite build process从 gulp-svg-sprite 构建过程中排除 SVG
【发布时间】:2018-07-15 15:06:38
【问题描述】:

我目前正在使用 gulp-svg-sprite 构建一个 SVG 图标系统,并且遇到了需要从构建过程中排除一些图标的情况。

有没有办法排除 SVG 从这两个管道中运行?不知何故,我需要获取 src 文件名并将其与要排除的 SVG 进行比较,例如:

if src != svgToExclude then run the pipes.

我不希望通过 SVGO 和其他插件对需要 2 条可样式化路径的 1-off SVG 优化特定图标。

这是我正在使用的代码:

const gulp = require('gulp');
const svgo = require('gulp-svgo');
const rsp = require('remove-svg-properties').stream;
const dom = require('gulp-dom');
const xmlEdit = require('gulp-edit-xml');
const gulpIf = require('gulp-if');
const gulpIgnore = require('gulp-ignore');
const { toPath } = require('svg-points');

var excludeIcon = './utilities/checkbox-checked/checkbox-checked--s.svg';

const svgBuild = src => {
  return gulp
    .src(src)
    .pipe(
      rsp.remove({
        properties: ['fill', rsp.PROPS_STROKE],
        log: false,
      })
    )
    .pipe(
      svgo({
        js2svg: {
          indent: 2,
          pretty: true,
        },
        plugins: [{ removeTitle: true }],
      })
    )
};

module.exports = svgBuild;

我是 gulp & node 的新手,所以任何帮助都将不胜感激!

谢谢, - 瑞恩

【问题讨论】:

    标签: svg gulp icons sprite svg-sprite


    【解决方案1】:

    使用gulp-filter:

    const filter = require('gulp-filter');
    

    类似

    var excludeIconArray = ["iconToExclude1.svg", "iconToExclude2.svg", etc.]
    
    const svgBuild = src => {
    
      const svgFilter = filter(file => {
    
        // will probably need file.path string manipulations here
        // file.path is the full path but you can select portions of it
        //  so the below is just pseudocode
    
        return !excludeIconArray.includes(file.path)
    });
    
      return gulp
        .src(src)
    
    // put the next pipe wherever you want to exclude certain files
    // either right after source or just before the svgo pipe
    
    .pipe(svgFilter())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 2018-03-17
      • 2019-10-03
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      相关资源
      最近更新 更多