scripts/node/build-icons.js
function optimizeSVGs(src) {
  const startOptimizeTaskName = swlog.logSubStart('optimize SVGs');

  // Optimize with svgo:
  const svgoOptimize = new svgo({
    js2svg: { useShortTags: false },
    plugins: [
      { removeViewBox: false },
      { convertColors: { currentColor: '#000000' }},
      { removeDimensions: true },
      { moveGroupAttrsToElems: true },
      { removeUselessStrokeAndFill: true },
      { customSvgoRemoveGroupFill },
      { customSvgoNonScalingStroke },
      { customSvgoFillStroke }
    ]
  });

  const svgFiles = glob.sync(`${src}/*.svg`);

  // Divide each optimization into a promise
  const svgPromises = svgFiles.map(async filepath => {
    try {
      const data = await readFile(filepath, 'utf8');
      const dataOptimized = await svgoOptimize.optimize(data);

      await writeFile(filepath, dataOptimized.data, 'utf-8');
    } catch(err) {
      swlog.error(err);
    }
  });

  return Promise.all(svgPromises).then(() => {
    swlog.logSubEnd(startOptimizeTaskName);
  }).catch(swlog.error);
}
function optimizeSVGs(src) {
  const startOptimizeTaskName = swlog.logSubStart('optimize SVGs');

  // Optimize with svgo:
  const svgoOptimize = new svgo({
    js2svg: { useShortTags: false },
    plugins: [
      { removeViewBox: false },
      { convertColors: { currentColor: '#000000' }},
      { removeDimensions: true },
      { moveGroupAttrsToElems: true },
      { removeUselessStrokeAndFill: true },
      { customSvgoRemoveGroupFill },
      { customSvgoNonScalingStroke },
      { customSvgoFillStroke }
    ]
  });

  const svgFiles = glob.sync(`${src}/*.svg`);

  // Divide each optimization into a promise
  const svgPromises = svgFiles.map(async filepath => {
    try {
      const data = await readFile(filepath, 'utf8');
      const dataOptimized = await svgoOptimize.optimize(data);

      await writeFile(filepath, dataOptimized.data, 'utf-8');
    } catch(err) {
      swlog.error(err);
    }
  });

  return Promise.all(svgPromises).then(() => {
    swlog.logSubEnd(startOptimizeTaskName);
  }).catch(swlog.error);
}
function optimizeSVGs ( src ) { const startOptimizeTaskName = swlog . logSubStart ( 'optimize SVGs' ) ; // Optimize with svgo: const svgoOptimize = new svgo ( { js2svg : { useShortTags : false } , plugins : [ { removeViewBox : false } , { convertColors : { currentColor : '#000000' } } , { removeDimensions : true } , { moveGroupAttrsToElems : true } , { removeUselessStrokeAndFill : true } , { customSvgoRemoveGroupFill } , { customSvgoNonScalingStroke } , { customSvgoFillStroke } ] } ) ; const svgFiles = glob . sync ( ` ${ src } ` ) ; // Divide each optimization into a promise const svgPromises = svgFiles . map ( async filepath => { try { const data = await readFile ( filepath , 'utf8' ) ; const dataOptimized = await svgoOptimize . optimize ( data ) ; await writeFile ( filepath , dataOptimized . data , 'utf-8' ) ; } catch ( err ) { swlog . error ( err ) ; } } ) ; return Promise . all ( svgPromises ) . then ( ( ) => { swlog . logSubEnd ( startOptimizeTaskName ) ; } ) . catch ( swlog . error ) ; }
Optimize the generated .svg icon files
@param {String} src - The source directory for svgs
Optimize the generated . svg icon files