From e048c9df9cba019e56fe1104791e8ae4464f5591 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 9 Mar 2022 08:32:42 +0000 Subject: [PATCH] adding ?skipsvgo url option --- README.md | 7 +++++++ index.d.ts | 5 +++++ index.js | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 356123e..d225eb3 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ import IconComponent from './my-icon.svg?component' // ``` +### 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' +``` + ### SVGO Configuration #### `vite.config.js` ```js diff --git a/index.d.ts b/index.d.ts index acd3840..323e0b5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,3 +20,8 @@ declare module '*.svg?raw' { const src: string export default src } + +declare module '*.svg?skipsvgo' { + const src: string + export default src +} diff --git a/index.js b/index.js index 2041e29..ac4b706 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const { optimize: optimizeSvg } = require('svgo') module.exports = function svgLoader (options = {}) { const { svgoConfig, svgo } = options - const svgRegex = /\.svg(\?(raw|component))?$/ + const svgRegex = /\.svg(\?(raw|component|skipsvgo))?$/ return { name: 'svg-loader', @@ -30,7 +30,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 }