From 5d8b6bd4ce3042c9716c9923469c342bc0ad4da2 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Tue, 5 Nov 2024 23:24:04 +0300 Subject: [PATCH] Update index.js --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index a2ae141..1175bc6 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ const svgrPlugin = (options = {}) => ({ name: 'svgr', setup(build) { build.onResolve({ filter: /\.svg$/ }, async (args) => { + if (build.bundle) { switch (args.kind) { case 'import-statement': case 'require-call': @@ -16,15 +17,14 @@ const svgrPlugin = (options = {}) => ({ external: true, } } + } }) build.onLoad({ filter: /\.svg$/ }, async (args) => { - const svg = await readFile(args.path, { encoding: 'utf8' }) - - if (options.plugins && !options.plugins.includes('@svgr/plugin-jsx')) { + const svg = await readFile(args.path, 'utf8') + options.plugins ||= [] + if (!options.plugins.includes('@svgr/plugin-jsx')) { options.plugins.push('@svgr/plugin-jsx') - } else if (!options.plugins) { - options.plugins = ['@svgr/plugin-jsx'] } const contents = await transform(svg, { ...options }, { filePath: args.path })