Skip to content

Commit

Permalink
Merge pull request #43 from mdunisch/main
Browse files Browse the repository at this point in the history
adding ?skipsvgo url option
  • Loading branch information
jpkleemans committed Aug 18, 2022
2 parents 8db398d + 0c7e9dd commit 20acc72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,13 @@ import IconComponent from './my-icon.svg?component'
// <IconComponent />
```

### Skip SVGO Optimizer for a file
SVGO can be explicitly disabled for one file by adding the `?skipsvgo` suffix:
```js
import IconWithoutOptimizer from './my-icon.svg?skipsvgo'
// <IconWithoutOptimizer />
```

### Default import config
When no explicit params are provided SVGs will be imported as Vue components by default.
This can be changed using the `defaultImport` config setting,
Expand Down
8 changes: 7 additions & 1 deletion index.d.ts
@@ -1,3 +1,5 @@
import { FunctionalComponent, SVGAttributes } from 'vue'

declare module 'vite-svg-loader' {
import { Plugin } from 'vite'
import { OptimizeOptions } from 'svgo'
Expand All @@ -6,7 +8,6 @@ declare module 'vite-svg-loader' {
}

declare module '*.svg?component' {
import { FunctionalComponent, SVGAttributes } from 'vue'
const src: FunctionalComponent<SVGAttributes>
export default src
}
Expand All @@ -20,3 +21,8 @@ declare module '*.svg?raw' {
const src: string
export default src
}

declare module '*.svg?skipsvgo' {
const src: FunctionalComponent<SVGAttributes>
export default src
}
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -5,7 +5,7 @@ const { optimize: optimizeSvg } = require('svgo')
module.exports = function svgLoader (options = {}) {
const { svgoConfig, svgo, defaultImport } = options

const svgRegex = /\.svg(\?(raw|component))?$/
const svgRegex = /\.svg(\?(raw|component|skipsvgo))?$/

return {
name: 'svg-loader',
Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = function svgLoader (options = {}) {
return `export default ${JSON.stringify(svg)}`
}

if (svgo !== false) {
if (svgo !== false && query !== 'skipsvgo') {
svg = optimizeSvg(svg, svgoConfig).data
}

Expand Down

0 comments on commit 20acc72

Please sign in to comment.