From 794c7978f0c63cae9b541574cdfb055a7afebd3f Mon Sep 17 00:00:00 2001 From: sunyiteng Date: Fri, 11 Oct 2024 11:56:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20`output.sourceMap`=20=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/spotty-mirrors-knock.md | 7 ++++ .../src/shared/parseCommonConfig.ts | 2 ++ .../src/shared/plugins/devtools.ts | 35 +++++++++++++------ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .changeset/spotty-mirrors-knock.md diff --git a/.changeset/spotty-mirrors-knock.md b/.changeset/spotty-mirrors-knock.md new file mode 100644 index 000000000000..f9785d54108d --- /dev/null +++ b/.changeset/spotty-mirrors-knock.md @@ -0,0 +1,7 @@ +--- +'@modern-js/uni-builder': patch +--- + +fix: `output.sourcemap` not work + +fix: `output.sourcemap` δΈη”Ÿζ•ˆ diff --git a/packages/cli/uni-builder/src/shared/parseCommonConfig.ts b/packages/cli/uni-builder/src/shared/parseCommonConfig.ts index 288f28d5ba72..fe6f598b50f9 100644 --- a/packages/cli/uni-builder/src/shared/parseCommonConfig.ts +++ b/packages/cli/uni-builder/src/shared/parseCommonConfig.ts @@ -95,6 +95,7 @@ export async function parseCommonConfig( enableAssetFallback, enableAssetManifest, disableSourceMap, + sourceMap, convertToRem, disableMinimize, polyfill, @@ -326,6 +327,7 @@ export async function parseCommonConfig( pluginGlobalVars(globalVars), pluginDevtool({ disableSourceMap, + sourceMap, }), pluginEmitRouteFile(), pluginToml(), diff --git a/packages/cli/uni-builder/src/shared/plugins/devtools.ts b/packages/cli/uni-builder/src/shared/plugins/devtools.ts index 4c7cee5e17cd..806b6923da16 100644 --- a/packages/cli/uni-builder/src/shared/plugins/devtools.ts +++ b/packages/cli/uni-builder/src/shared/plugins/devtools.ts @@ -1,29 +1,42 @@ -import type { RsbuildPlugin } from '@rsbuild/core'; +import type { RsbuildPlugin, SourceMap } from '@rsbuild/core'; import type { DisableSourceMapOption } from '../../types'; const isUseJsSourceMap = (disableSourceMap: DisableSourceMapOption = {}) => { - return typeof disableSourceMap === 'boolean' - ? !disableSourceMap - : !disableSourceMap.js; + if (typeof disableSourceMap === 'boolean') { + return !disableSourceMap; + } + return !disableSourceMap.js; }; export const pluginDevtool = (options: { disableSourceMap?: DisableSourceMapOption; + sourceMap?: SourceMap; }): RsbuildPlugin => ({ name: 'uni-builder:devtool', setup(api) { api.modifyBundlerChain((chain, { isProd, isServer }) => { + // priority order + // 1. output.disableSourceMap if (!isUseJsSourceMap(options.disableSourceMap)) { chain.devtool(false); - } else { - const prodDevTool = isServer ? 'source-map' : 'hidden-source-map'; - const devtool = isProd - ? // hide the source map URL in production to avoid Chrome warning - prodDevTool - : 'cheap-module-source-map'; - chain.devtool(devtool); + return; } + + // 2. output.sourceMap + const devtoolJs = options.sourceMap?.js; + if (devtoolJs) { + chain.devtool(devtoolJs); + return; + } + + // 3. default behavior + const prodDevTool = isServer ? 'source-map' : 'hidden-source-map'; + const devtool = isProd + ? // hide the source map URL in production to avoid Chrome warning + prodDevTool + : 'cheap-module-source-map'; + chain.devtool(devtool); }); }, }); From 9091ce5d293565d2cec856da4caab123f0065d84 Mon Sep 17 00:00:00 2001 From: sunyiteng Date: Sat, 12 Oct 2024 11:32:54 +0800 Subject: [PATCH 2/3] chore: adopt suggestions --- .../src/shared/plugins/devtools.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/cli/uni-builder/src/shared/plugins/devtools.ts b/packages/cli/uni-builder/src/shared/plugins/devtools.ts index 806b6923da16..1c8e9eae60e8 100644 --- a/packages/cli/uni-builder/src/shared/plugins/devtools.ts +++ b/packages/cli/uni-builder/src/shared/plugins/devtools.ts @@ -1,3 +1,4 @@ +import { logger } from '@modern-js/utils'; import type { RsbuildPlugin, SourceMap } from '@rsbuild/core'; import type { DisableSourceMapOption } from '../../types'; @@ -15,21 +16,24 @@ export const pluginDevtool = (options: { name: 'uni-builder:devtool', setup(api) { + // priority order + // 1. output.sourceMap.js, if this value is set, we won't apply this plugin and let rsbuild handles it + const devtoolJs = options.sourceMap?.js; + if (devtoolJs) { + if (!isUseJsSourceMap(options.disableSourceMap)) { + logger.warn( + 'Detected that `output.sourceMap` and `output.disableSourceMap` are used together, use the value of `output.sourceMap`', + ); + } + return; + } api.modifyBundlerChain((chain, { isProd, isServer }) => { - // priority order - // 1. output.disableSourceMap + // 2. output.disableSourceMap if (!isUseJsSourceMap(options.disableSourceMap)) { chain.devtool(false); return; } - // 2. output.sourceMap - const devtoolJs = options.sourceMap?.js; - if (devtoolJs) { - chain.devtool(devtoolJs); - return; - } - // 3. default behavior const prodDevTool = isServer ? 'source-map' : 'hidden-source-map'; const devtool = isProd From e2e624aec9632d149e1e2ad191aaaf04186d57a5 Mon Sep 17 00:00:00 2001 From: sunyiteng Date: Sat, 12 Oct 2024 11:35:23 +0800 Subject: [PATCH 3/3] chore: add deprecated warning --- packages/cli/uni-builder/src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/uni-builder/src/types.ts b/packages/cli/uni-builder/src/types.ts index 6c9b6f7e4a02..5cfefbea90c8 100644 --- a/packages/cli/uni-builder/src/types.ts +++ b/packages/cli/uni-builder/src/types.ts @@ -290,6 +290,7 @@ export type UniBuilderExtraConfig = { disableSvgr?: boolean; /** * Whether to disable source map. + * @deprecated use `output.sourceMap` instead */ disableSourceMap?: DisableSourceMapOption; /**