diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index 4b09a31..ba75ae7 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -62,4 +62,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 f1073cb..5241595 100644 --- a/examples/vue/src/assets/test.svg +++ b/examples/vue/src/assets/test.svg @@ -2,12 +2,10 @@ - - - - + + + diff --git a/examples/vue/vite.config.js b/examples/vue/vite.config.js index 4d3f887..834b150 100644 --- a/examples/vue/vite.config.js +++ b/examples/vue/vite.config.js @@ -12,7 +12,18 @@ 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: [ + 'preset-default', + { name: 'prefixIds' }, + ], + } + }) + ], resolve: { alias: { diff --git a/index.js b/index.js index 29d9c1e..e43ce1f 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 @@ -38,7 +38,10 @@ module.exports = function svgLoader (options = {}) { } if (svgo !== false && query !== 'skipsvgo') { - svg = optimizeSvg(svg, svgoConfig).data + svg = optimize(svg, { + ...svgoConfig, + path + }).data } const { code } = compileTemplate({