From 625efa3adb16a29d9b07cdf040a7d9656d35386b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LeBlanc?= Date: Thu, 7 Jul 2022 13:55:00 -0400 Subject: [PATCH 1/4] Send path to svgo Fix #60 --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9eb8b07..155b26e 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const fs = require('fs').promises const { compileTemplate } = require('@vue/compiler-sfc') -const { optimize: optimizeSvg } = require('svgo') +const { optimize } = require("svgo"); module.exports = function svgLoader (options = {}) { const { svgoConfig, svgo, defaultImport } = options @@ -37,7 +37,10 @@ module.exports = function svgLoader (options = {}) { } if (svgo !== false) { - svg = optimizeSvg(svg, svgoConfig).data + svg = optimize(svg, { + ...svgoConfig, + path, + }).data } const { code } = compileTemplate({ From 1e058856a73ebf319888e8843db2713e7646b729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LeBlanc?= Date: Mon, 18 Jul 2022 16:00:25 -0400 Subject: [PATCH 2/4] Lint --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 155b26e..370a77b 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const fs = require('fs').promises const { compileTemplate } = require('@vue/compiler-sfc') -const { optimize } = require("svgo"); +const { optimize } = require('svgo') module.exports = function svgLoader (options = {}) { const { svgoConfig, svgo, defaultImport } = options @@ -39,7 +39,7 @@ module.exports = function svgLoader (options = {}) { if (svgo !== false) { svg = optimize(svg, { ...svgoConfig, - path, + path }).data } From 15b16e829be274b57ba947c84abd267ba99b30f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LeBlanc?= Date: Mon, 18 Jul 2022 16:20:06 -0400 Subject: [PATCH 3/4] Add cypress test --- cypress/integration/spec.js | 4 ++++ examples/vue/src/assets/test.svg | 11 ++++------- examples/vue/vite.config.js | 12 +++++++++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index c6feff2..36390a7 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -52,4 +52,8 @@ describe('Vite SVG Loader', () => { expect($img[0].width).to.equal(355) }) }) + + it("it send path to svgo", () => { + cy.get("#component svg .test_svg__rectangle").should("exist"); + }); }) diff --git a/examples/vue/src/assets/test.svg b/examples/vue/src/assets/test.svg index 4578342..fe3ce39 100644 --- a/examples/vue/src/assets/test.svg +++ b/examples/vue/src/assets/test.svg @@ -2,12 +2,9 @@ - - - - + + + diff --git a/examples/vue/vite.config.js b/examples/vue/vite.config.js index 4d3f887..178955e 100644 --- a/examples/vue/vite.config.js +++ b/examples/vue/vite.config.js @@ -12,7 +12,17 @@ export default defineConfig(({ mode }) => { const DEFAULT_IMPORT = env.VITE_SVG_DEFAULT_IMPORT || env.npm_config_svg_default_import return { - plugins: [vue(), viteSvgLoader({ defaultImport: DEFAULT_IMPORT })], + plugins: [ + vue(), + viteSvgLoader({ + defaultImport: DEFAULT_IMPORT, + svgoConfig: { + plugins: [ + { name: 'prefixIds' }, + ], + } + }) + ], resolve: { alias: { From 30c6d0490cc98b9614deed94e42f19edcb174b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LeBlanc?= Date: Wed, 31 Aug 2022 16:35:29 -0400 Subject: [PATCH 4/4] [FIX] Extend svgo defaults --- examples/vue/vite.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/vue/vite.config.js b/examples/vue/vite.config.js index 178955e..834b150 100644 --- a/examples/vue/vite.config.js +++ b/examples/vue/vite.config.js @@ -18,6 +18,7 @@ export default defineConfig(({ mode }) => { defaultImport: DEFAULT_IMPORT, svgoConfig: { plugins: [ + 'preset-default', { name: 'prefixIds' }, ], }