SVGs added but "result" is empty on compile
giladbr opened this issue · comments
Gilad Bar Ner commented
Trying different configurations and files, opened verbose logging, but no matter what I do the result
still comes out an empty object. No error
or data
either.
let options = {
dest: '.',
log: 'verbose',
shape: { transform: [] }, //Default SVG optimization causes exception in "svgo", so disable it with empty array
};
const spriter = new SVGSpriter(options);
Object.keys(SVGs).forEach((filename) => {
//SVG-sprite only works with actual files, so we need to write the string to a file and read from it
const tempSVGdir = path.join(__dirname, "/tempSVG/");
if (!fs.existsSync(tempSVGdir)) {
fs.mkdirSync(tempSVGdir);
}
const path_ = path.join(tempSVGdir, `${filename}.svg`);
fs.writeFileSync(path_, SVGs[filename]);
spriter.add(path_, null, fs.readFileSync(path_));
});
// spriter.getShapes(__dirname, (error,result) => { //To view SVGs before compile
// console.log(result); //This shows the SVGs works
// });
spriter.compile(options, (error, result, data) => {
console.log(result); //EMPTY OBJECT!!!!
for (const mode in result) {
for (const resource in result[mode]) {
sprite += result[mode][resource].contents.toString();
}
}
});
Logs:
2022-05-21 20:05:25.305 - verbose: Initialized spriter configuration
2022-05-21 20:05:25.308 - info: Created spriter instance
2022-05-21 20:05:25.322 - verbose: Added shape "cebook:regular"
2022-05-21 20:05:25.337 - verbose: Added shape "utube:regular"
2022-05-21 20:05:25.348 - verbose: Added shape "itter:regular"
2022-05-21 20:05:25.360 - verbose: Added shape "UPABOVE:regular"
2022-05-21 20:05:25.362 - info: Compiling 4 shapes ...
2022-05-21 20:05:25.379 - info: Finished sprite compilation
2022-05-21 20:05:25.381 - info: Created
Gilad Bar Ner commented
Changed to:
let options = {
log: 'verbose',
transform: [], //Default SVG optimization causes exception in "svgo", so disable it with empty array
mode: {
symbol: true
}
};
[...]
spriter.compile((error, result, data) => {
And now result
(and data
) are not empty. Not sure why. Something about the mode
, which is weird because I also tried playing with it and to no avail. But now it works.