Skip to content

Commit

Permalink
Merge pull request #61 from mrleblanc101/main
Browse files Browse the repository at this point in the history
Send path to svgo
  • Loading branch information
jpkleemans committed Sep 1, 2022
2 parents 8de7ff9 + 30c6d04 commit ce3e75e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cypress/integration/spec.js
Expand Up @@ -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");
});
})
12 changes: 5 additions & 7 deletions examples/vue/src/assets/test.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion examples/vue/vite.config.js
Expand Up @@ -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: {
Expand Down
7 changes: 5 additions & 2 deletions 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
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit ce3e75e

Please sign in to comment.