-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release-v2.60.3
- Loading branch information
Showing
4 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` 不生效 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters