rspack
                                
                                
                                
                                    rspack copied to clipboard
                            
                            
                            
                        [Bug]: `this.sourceMap` in the LoaderContext is `false` when using SourceMapDevToolPlugin
System Info
System: OS: macOS 14.6.1 CPU: (12) arm64 Apple M2 Max Memory: 30.78 GB / 96.00 GB Shell: 3.7.1 - /opt/homebrew/bin/fish npmPackages: @rspack/cli: ^1.0.5 => 1.0.5 @rspack/core: ^1.0.5 => 1.0.5
Details
I'm using custom configuration of SourceMapDevToolPlugin, both Webpack and Rspack documentation shows that I should set devtool: false.
https://webpack.js.org/plugins/source-map-dev-tool-plugin/#root https://rspack.dev/plugins/webpack/source-map-dev-tool-plugin
But after I set devtool: false, I found the source-map is not correctly generated.
After dive into the compilation process, I found that is caused by the this.sourceMap changes to false in my custom loader.
// loader.js
export default function(content) {
  const callback = this.async()
  const result = transform(content, { sourceMap: this.sourceMap }) // this.sourceMap === false
  callback(null, result.code, result.map) // result.map === false, result in no source-map generated
}
The Rspack directly use devtool to setup loaderContext.sourceMap:
https://github.com/web-infra-dev/rspack/blob/2ec06e47b22f6678c0f921dc30573d3dc305ca18/packages/rspack/src/loader-runner/index.ts#L556-L558
But Webpack will update the value in the SourceMapDevToolModuleOptionsPlugin:
https://github.com/webpack/webpack/blob/dae16ad11e2d2accddc549a92082da3d2e667b01/lib/SourceMapDevToolModuleOptionsPlugin.js#L31
Reproduce link
https://github.com/colinaaa-reproductions/rspack-loader-context-sourcemap
Reproduce Steps
- Run 
pnpm install - Run 
pnpm build:webpack - Run 
node webpack-dist/main.js// showtrue - Run 
pnpm build:rspack - Run 
node rspack-dist/main.js// showfalse