Skip to content

Commit

Permalink
adding ?skipsvgo url option
Browse files Browse the repository at this point in the history
  • Loading branch information
mdunisch committed May 2, 2022
1 parent 816f309 commit aaf1c2d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 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'
// '/assets/my-icon.2d8efhg.svg'
```

### 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
5 changes: 5 additions & 0 deletions index.d.ts
Expand Up @@ -20,3 +20,8 @@ declare module '*.svg?raw' {
const src: string
export default src
}

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

let viteConfig = {}
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 aaf1c2d

Please sign in to comment.