Skip to content

Commit

Permalink
fix: swc-loader options.sourceMaps not work (web-infra-dev#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

0 comments on commit 599ce46

Please sign in to comment.