Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/plugin-svgr/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
import { PLUGIN_REACT_NAME } from '@rsbuild/plugin-react';
import type { Config as BaseSvgrOptions } from '@svgr/core';
Expand All @@ -12,8 +11,6 @@ type SvgrOptions = Omit<BaseSvgrOptions, 'svgoConfig'> & {
svgoConfig?: SvgoConfig;
};

const __dirname = path.dirname(fileURLToPath(import.meta.url));

type SvgoPluginConfig = NonNullable<SvgoConfig['plugins']>[0];

export type SvgDefaultExport = 'component' | 'url';
Expand Down Expand Up @@ -211,7 +208,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
.type('javascript/auto')
.resourceQuery(options.query || /react/)
.use(CHAIN_ID.USE.SVGR)
.loader(path.resolve(__dirname, './loader.mjs'))
.loader(path.join(import.meta.dirname, 'loader.mjs'))
Comment thread
chenjiahan marked this conversation as resolved.
.options({
...svgrOptions,
exportType: 'default',
Expand Down Expand Up @@ -242,7 +239,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
// The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
.set('issuer', issuer)
.use(CHAIN_ID.USE.SVGR)
.loader(path.resolve(__dirname, './loader.mjs'))
.loader(path.join(import.meta.dirname, 'loader.mjs'))
.options({
...svgrOptions,
exportType,
Expand All @@ -256,7 +253,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
if (mixedImport && exportType === 'named') {
svgRule
.use(CHAIN_ID.USE.URL)
.loader(path.resolve(__dirname, './assetLoader.mjs'))
.loader(path.join(import.meta.dirname, 'assetLoader.mjs'))
.options({
limit: maxSize,
name: generatorOptions?.filename,
Expand Down
Loading