Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builder): output.sourceMap not work #6342

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -326,6 +327,7 @@ export async function parseCommonConfig(
pluginGlobalVars(globalVars),
pluginDevtool({
disableSourceMap,
sourceMap,
SoonIter marked this conversation as resolved.
Show resolved Hide resolved
}),
pluginEmitRouteFile(),
pluginToml(),
Expand Down
35 changes: 24 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,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);
});
},
});
Loading