Skip to content

Commit

Permalink
fix: swc-loader options.sourceMaps not work (#6317)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Apr 22, 2024
1 parent 759bbdf commit 599ce46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 6 additions & 1 deletion crates/rspack_loader_swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rspack_plugin_javascript::ast::{self, SourceMapConfig};
use rspack_plugin_javascript::TransformOutput;
use rspack_util::source_map::SourceMapKind;
use swc_config::{config_types::MergingOption, merge::Merge};
use swc_core::base::config::SourceMapsConfig;
use swc_core::base::config::{InputSourceMap, OutputCharset, TransformConfig};

#[derive(Debug)]
Expand Down Expand Up @@ -79,7 +80,11 @@ impl Loader<LoaderRunnerContext> for SwcLoader {
swc_options
};

let source_map_kind = &loader_context.context.module_source_map_kind;
let source_map_kind: &SourceMapKind = match swc_options.config.source_maps {
Some(SourceMapsConfig::Bool(false)) => &SourceMapKind::None,
_ => &loader_context.context.module_source_map_kind,
};

let source = content.try_into_string()?;
let c = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options)
.map_err(AnyhowError::from)?;
Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/guide/builtin-swc-loader.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiMeta, Stability } from '../../../components/ApiMeta';

<ApiMeta addedVersion="0.3.0" />

`builtin:swc-loader` is the Rust version of [`swc-loader`](https://github.com/swc-project/pkgs/tree/main/packages/swc-loader), aiming to deliver better performance. The Loader's [configuration](https://swc.rs/docs/configuration/compilation) is aligned with the JS version of `swc-loader` (SWC plugins will be provided in future releases and are currently not supported).
`builtin:swc-loader` is the Rust version of [`swc-loader`](https://github.com/swc-project/pkgs/tree/main/packages/swc-loader), aiming to deliver better performance. The Loader's [configuration](https://swc.rs/docs/configuration/compilation) is aligned with the JS version of `swc-loader`.

## Example

Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = {
use: {
loader: 'builtin:swc-loader',
options: {
sourceMap: true,
sourceMaps: true,
jsc: {
parser: {
syntax: 'ecmascript',
Expand Down
7 changes: 3 additions & 4 deletions website/docs/zh/guide/builtin-swc-loader.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { ApiMeta, Stability } from '../../../components/ApiMeta';

<ApiMeta addedVersion="0.3.0" />

`builtin:swc-loader`[`swc-loader`](https://github.com/swc-project/pkgs/tree/main/packages/swc-loader) 的 Rust 版本,旨在提供更优的性能,
Loader 的[配置](https://swc.rs/docs/configuration/compilation)与 JS 版本的 `swc-loader` 保持对齐(SWC 插件将会在未来版本进行提供,暂不支持)。
`builtin:swc-loader`[`swc-loader`](https://github.com/swc-project/pkgs/tree/main/packages/swc-loader) 的 Rust 版本,旨在提供更优的性能,Loader 的[配置](https://swc.rs/docs/configuration/compilation)与 JS 版本的 `swc-loader` 保持对齐。

## 示例

Expand Down Expand Up @@ -36,7 +35,7 @@ module.exports = {
};
```

或是对 `js` 文件进行转译:
或是对 `jsx` 文件进行转译:

```js
module.exports = {
Expand All @@ -47,7 +46,7 @@ module.exports = {
use: {
loader: 'builtin:swc-loader',
options: {
sourceMap: true,
sourceMaps: true,
jsc: {
parser: {
syntax: 'ecmascript',
Expand Down

3 comments on commit 599ce46

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-04-22 72638cb) Current Change
10000_development-mode + exec 2.67 s ± 31 ms 2.65 s ± 26 ms -0.60 %
10000_development-mode_hmr + exec 685 ms ± 7.4 ms 684 ms ± 3.5 ms -0.16 %
10000_production-mode + exec 2.46 s ± 29 ms 2.5 s ± 26 ms +1.65 %
arco-pro_development-mode + exec 2.47 s ± 80 ms 2.48 s ± 78 ms +0.69 %
arco-pro_development-mode_hmr + exec 429 ms ± 1.3 ms 429 ms ± 1.2 ms -0.15 %
arco-pro_development-mode_hmr_intercept-plugin + exec 440 ms ± 4.1 ms 439 ms ± 2.6 ms -0.22 %
arco-pro_development-mode_intercept-plugin + exec 3.23 s ± 71 ms 3.24 s ± 74 ms +0.26 %
arco-pro_production-mode + exec 3.93 s ± 107 ms 3.98 s ± 87 ms +1.12 %
arco-pro_production-mode_intercept-plugin + exec 4.73 s ± 74 ms 4.78 s ± 83 ms +0.96 %
threejs_development-mode_10x + exec 2.05 s ± 21 ms 2.06 s ± 20 ms +0.25 %
threejs_development-mode_10x_hmr + exec 746 ms ± 11 ms 767 ms ± 5.8 ms +2.85 %
threejs_production-mode_10x + exec 5.16 s ± 40 ms 5.2 s ± 46 ms +0.84 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

Please sign in to comment.