svg-sprite / svg-sprite

SVG sprites & stacks galore — A low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types along with suitable stylesheet resources (e.g. CSS, Sass, LESS, Stylus, etc.)

Home Page:https://github.com/svg-sprite/svg-sprite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting exceptions on "add" - unknown error, open '//../../.svgo.yml'

giladbr opened this issue · comments

My SVGs are coming from strings, and since the library only works with buffers\files, I tried the following code:
` Object.keys(SVGs).forEach((filename) => {

        const path_ = path.join(__dirname, filename);
        fs.writeFileSync(path_, SVGs[filename]);
        // spriter.add(path_, null, fs.readFileSync(path_)); //tried that too
           spriter.add(new File({
              path: path_,
              base: __dirname, // Base path (see `name` argument)
              // contents: Buffer.from(SVGs[filename], "utf-8") //tried that too
              contents: fs.readFileSync(path_)
          }));
     });

But getting exception UNKNOWN: unknown error, open '//../../.svgo.yml'.
Tried other things too...
Also, where is svgo.yml?

Turns out the exception was caused by SVG optimization - I found it out by googling "svgo" and realizing it's a dependency for optimizing the svgs that's in the node_modules. I disabled it in the config by supplying an empty array: const spriter = new SVGSpriter({ shape: { transform: [] } }); and the exception's gone.