Skip to content

Commit

Permalink
Merge branch 'main' into release-v2.60.3
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin authored Oct 12, 2024
2 parents e72db08 + d7e932a commit 0234000
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/spotty-mirrors-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/uni-builder': patch
---

fix: `output.sourcemap` not work

fix: `output.sourcemap` 不生效
2 changes: 2 additions & 0 deletions packages/cli/uni-builder/src/shared/parseCommonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function parseCommonConfig(
enableAssetFallback,
enableAssetManifest,
disableSourceMap,
sourceMap,
convertToRem,
disableMinimize,
polyfill,
Expand Down Expand Up @@ -328,6 +329,7 @@ export async function parseCommonConfig(
pluginGlobalVars(globalVars),
pluginDevtool({
disableSourceMap,
sourceMap,
}),
pluginEmitRouteFile(),
pluginToml(),
Expand Down
39 changes: 28 additions & 11 deletions packages/cli/uni-builder/src/shared/plugins/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import { logger } from '@modern-js/utils';
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) {
// 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 }) => {
// 2. 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;
}

// 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);
});
},
});
1 change: 1 addition & 0 deletions packages/cli/uni-builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export type UniBuilderExtraConfig = {
disableSvgr?: boolean;
/**
* Whether to disable source map.
* @deprecated use `output.sourceMap` instead
*/
disableSourceMap?: DisableSourceMapOption;
/**
Expand Down

0 comments on commit 0234000

Please sign in to comment.