Skip to content

Commit c6d430f

Browse files
authored
refactor(plugin-svgr): use import.meta.dirname for loaders (#7483)
1 parent 1b311e9 commit c6d430f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/plugin-svgr/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'node:path';
2-
import { fileURLToPath } from 'node:url';
32
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
43
import { PLUGIN_REACT_NAME } from '@rsbuild/plugin-react';
54
import type { Config as BaseSvgrOptions } from '@svgr/core';
@@ -12,8 +11,6 @@ type SvgrOptions = Omit<BaseSvgrOptions, 'svgoConfig'> & {
1211
svgoConfig?: SvgoConfig;
1312
};
1413

15-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
16-
1714
type SvgoPluginConfig = NonNullable<SvgoConfig['plugins']>[0];
1815

1916
export type SvgDefaultExport = 'component' | 'url';
@@ -211,7 +208,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
211208
.type('javascript/auto')
212209
.resourceQuery(options.query || /react/)
213210
.use(CHAIN_ID.USE.SVGR)
214-
.loader(path.resolve(__dirname, './loader.mjs'))
211+
.loader(path.join(import.meta.dirname, 'loader.mjs'))
215212
.options({
216213
...svgrOptions,
217214
exportType: 'default',
@@ -242,7 +239,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
242239
// The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
243240
.set('issuer', issuer)
244241
.use(CHAIN_ID.USE.SVGR)
245-
.loader(path.resolve(__dirname, './loader.mjs'))
242+
.loader(path.join(import.meta.dirname, 'loader.mjs'))
246243
.options({
247244
...svgrOptions,
248245
exportType,
@@ -256,7 +253,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
256253
if (mixedImport && exportType === 'named') {
257254
svgRule
258255
.use(CHAIN_ID.USE.URL)
259-
.loader(path.resolve(__dirname, './assetLoader.mjs'))
256+
.loader(path.join(import.meta.dirname, 'assetLoader.mjs'))
260257
.options({
261258
limit: maxSize,
262259
name: generatorOptions?.filename,

0 commit comments

Comments
 (0)