Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ?skipsvgo url option #43

Merged
merged 2 commits into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -36,7 +36,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