From 3aede0bc1a4c79ae003fb7ae72c06254477701bb Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 25 Sep 2020 18:00:28 +0200 Subject: [PATCH] Fixed relative icon path loading for webpack with file paths (e.g. use with electron) --- package.json | 2 +- plugin/generator.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7723865..74cc075 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin/generator.ts b/plugin/generator.ts index e81b012..ad9d395 100644 --- a/plugin/generator.ts +++ b/plugin/generator.ts @@ -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}`;