From d3c6035782cbf8bf76078acedf2320d1c458770c Mon Sep 17 00:00:00 2001 From: George Date: Fri, 19 May 2023 09:29:12 +0300 Subject: [PATCH] Small refactoring --- index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index b31b14c..d39b473 100644 --- a/index.js +++ b/index.js @@ -2,17 +2,15 @@ const fs = require('fs').promises const { compileTemplate } = require('vue/compiler-sfc') const { optimize: optimizeSvg } = require('svgo') -module.exports = function svgLoader (options = {}) { +module.exports = function svgLoader(options = {}) { const { svgoConfig, svgo, defaultImport } = options - const svgRegex = /\.svg(\?(raw|component|skipsvgo))?$/ - return { name: 'svg-loader', enforce: 'pre', - async load (id) { - if (!id.match(svgRegex)) { + async load(id) { + if (!id.endsWith('.svg')) { return } @@ -29,7 +27,10 @@ module.exports = function svgLoader (options = {}) { try { svg = await fs.readFile(path, 'utf-8') } catch (ex) { - console.warn('\n', `${id} couldn't be loaded by vite-svg-loader, fallback to default loader`) + console.warn( + '\n', + `${id} couldn't be loaded by vite-svg-loader, fallback to default loader` + ) return } @@ -40,22 +41,24 @@ module.exports = function svgLoader (options = {}) { if (svgo !== false && query !== 'skipsvgo') { svg = optimizeSvg(svg, { ...svgoConfig, - path + path, }).data } // To prevent compileTemplate from removing the style tag - svg = svg.replace(/