From 4f5e1c0b9c9c32cc83cbd49add5b678fe8a19f68 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 24 May 2024 13:21:28 +0200 Subject: [PATCH] fix: sourcemap generation for story files --- .../src/loaders/export-order-loader.ts | 4 +--- .../src/loaders/react-docgen-loader.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/builder-rsbuild/src/loaders/export-order-loader.ts b/packages/builder-rsbuild/src/loaders/export-order-loader.ts index 5188a56..201997f 100644 --- a/packages/builder-rsbuild/src/loaders/export-order-loader.ts +++ b/packages/builder-rsbuild/src/loaders/export-order-loader.ts @@ -50,9 +50,7 @@ export default async function loader( ) } - const generatedMap = magicString.generateMap({ hires: true }) - - return callback(null, magicString.toString(), generatedMap, meta) + return callback(null, magicString.toString(), map, meta) } catch (err) { return callback(null, source, map, meta) } diff --git a/packages/react-rsbuild/src/loaders/react-docgen-loader.ts b/packages/react-rsbuild/src/loaders/react-docgen-loader.ts index bb4a63a..e21e638 100644 --- a/packages/react-rsbuild/src/loaders/react-docgen-loader.ts +++ b/packages/react-rsbuild/src/loaders/react-docgen-loader.ts @@ -100,6 +100,7 @@ let matchPath: TsconfigPaths.MatchPath | undefined export default async function reactDocgenLoader( this: LoaderContext<{ debug: boolean }>, source: string, + map: any, ) { const callback = this.async() // get options @@ -149,11 +150,16 @@ export default async function reactDocgenLoader( } }) - const map = magicString.generateMap({ - includeContent: true, - source: this.resourcePath, - }) - callback(null, magicString.toString(), map) + callback( + null, + magicString.toString(), + map ?? + magicString.generateMap({ + hires: true, + source: this.resourcePath, + includeContent: true, + }), + ) } catch (error: any) { if (error.code === ERROR_CODES.MISSING_DEFINITION) { callback(null, source)