Skip to content

Commit ce3e75e

Browse files
authored
Merge pull request #61 from mrleblanc101/main
Send path to svgo
2 parents 8de7ff9 + 30c6d04 commit ce3e75e

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

cypress/integration/spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ describe('Vite SVG Loader', () => {
6262
expect($img[0].width).to.equal(355)
6363
})
6464
})
65+
66+
it("it send path to svgo", () => {
67+
cy.get("#component svg .test_svg__rectangle").should("exist");
68+
});
6569
})

examples/vue/src/assets/test.svg

Lines changed: 5 additions & 7 deletions
Loading

examples/vue/vite.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ export default defineConfig(({ mode }) => {
1212
const DEFAULT_IMPORT = env.VITE_SVG_DEFAULT_IMPORT || env.npm_config_svg_default_import
1313

1414
return {
15-
plugins: [vue(), viteSvgLoader({ defaultImport: DEFAULT_IMPORT })],
15+
plugins: [
16+
vue(),
17+
viteSvgLoader({
18+
defaultImport: DEFAULT_IMPORT,
19+
svgoConfig: {
20+
plugins: [
21+
'preset-default',
22+
{ name: 'prefixIds' },
23+
],
24+
}
25+
})
26+
],
1627

1728
resolve: {
1829
alias: {

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs').promises
22
const { compileTemplate } = require('@vue/compiler-sfc')
3-
const { optimize: optimizeSvg } = require('svgo')
3+
const { optimize } = require('svgo')
44

55
module.exports = function svgLoader (options = {}) {
66
const { svgoConfig, svgo, defaultImport } = options
@@ -38,7 +38,10 @@ module.exports = function svgLoader (options = {}) {
3838
}
3939

4040
if (svgo !== false && query !== 'skipsvgo') {
41-
svg = optimizeSvg(svg, svgoConfig).data
41+
svg = optimize(svg, {
42+
...svgoConfig,
43+
path
44+
}).data
4245
}
4346

4447
const { code } = compileTemplate({

0 commit comments

Comments
 (0)