Fixed relative icon path loading for webpack with file paths (e.g. use with electron)

master
WolverinDEV 2020-09-25 18:00:28 +02:00
parent 0522e813b3
commit 3aede0bc1a
2 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "webpack-svg-sprite-generator",
"version": "1.0.16",
"version": "1.0.17",
"description": "",
"main": "plugin.js",
"types": "ts/index.d.ts",

View File

@ -93,7 +93,9 @@ export async function generateSpriteCss(options: SpriteCssOptions, classPrefix:
let result = "";
result += `${options.selector}{`;
result += `display:inline-block;`;
result += `background:url("${publicUrl}") no-repeat;`;
/* doing a relative path here as well since WebPack may messes around here since the public path may start with / and if it's a file path / means the root... */
result += `background-image:url(".${publicUrl}"),url("${publicUrl}");`;
result += `background-repeat:no-repeat;`;
result += `background-size:${sprite.width * scaleX}${options.unit} ${sprite.height * scaleY}${options.unit};`;
result += `height:${defaultHeight * scaleY}${options.unit};`;
result += `width:${defaultWidth * scaleX}${options.unit}`;