1

我目前正在使用 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 的新手,所以任何帮助都将不胜感激!

谢谢, - 瑞安

4

1 回答 1

0

使用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())
于 2018-02-05T21:45:34.933 回答