You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(loadable-components): Support aliased loadable imports (#585)
## Summary
This PR fixes the issue where the @swc/plugin-loadable-components plugin
would not transform `loadable()` calls when imported from vendored or
aliased packages.
## Changes
- Made the `from` field in the `Signature` struct optional
(`Option<Wtf8Atom>`)
- Updated `visit_mut_import_decl` to skip source checking when `from` is
`None`
- Added test cases for vendored/aliased loadable imports
- Updated documentation with usage examples
## Usage
To enable aliased imports, configure with a signature that omits the
`from` field:
```json
["loadable-components", { "signatures": [
{
"name": "loadable"
}
]}]
```
This matches the behavior of the official Babel plugin as documented in
the [Loadable
documentation](https://loadable-components.com/docs/babel-plugin/#loadable-detection).
Fixes#572
---
Generated with [Claude Code](https://claude.ai/code)) | [View
branch](https://github.com/swc-project/plugins/tree/claude/issue-572-20260117-0001)
| [View job
run](https://github.com/swc-project/plugins/actions/runs/21084641572
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
Copy file name to clipboardExpand all lines: packages/loadable-components/README.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,19 +8,40 @@
8
8
9
9
Sometimes you need to wrap loadable with your own custom logic. There are many use cases for it, from injecting telemetry to hiding external libraries behind facade.
10
10
By default `loadable-components` are configured to transform dynamic imports used only inside loadable helpers, but can be configured to instrument any other function of your choice.
11
+
12
+
### Custom signatures with specific package sources
13
+
11
14
```json
12
15
["loadable-components", { "signatures": [
13
16
{
14
17
"from": "myLoadableWrapper",
15
-
"name": "default"
18
+
"name": "default"
16
19
},
17
20
{
18
21
"from": "myLoadableWrapper",
19
-
"name": "lazy"
22
+
"name": "lazy"
20
23
}]
21
24
}]
22
25
```
23
26
27
+
### Custom signatures without package source (matches any import)
28
+
29
+
To match any import with a specific name regardless of the source package (useful for vendored or aliased packages), omit the `from` field:
30
+
31
+
```json
32
+
["loadable-components", { "signatures": [
33
+
{
34
+
"name": "loadable"
35
+
}]
36
+
}]
37
+
```
38
+
39
+
This will transform any default import named `loadable`, regardless of where it's imported from:
40
+
```js
41
+
importloadablefrom'my-vendored-loadable'; // will be transformed
42
+
importloadablefrom'@loadable/component'; // will be transformed
Copy file name to clipboardExpand all lines: packages/loadable-components/README.tmpl.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,38 @@
8
8
9
9
Sometimes you need to wrap loadable with your own custom logic. There are many use cases for it, from injecting telemetry to hiding external libraries behind facade.
10
10
By default `loadable-components` are configured to transform dynamic imports used only inside loadable helpers, but can be configured to instrument any other function of your choice.
11
+
12
+
### Custom signatures with specific package sources
13
+
11
14
```json
12
15
["loadable-components", { "signatures": [
13
16
{
14
17
"from": "myLoadableWrapper",
15
-
"name": "default"
18
+
"name": "default"
16
19
},
17
20
{
18
21
"from": "myLoadableWrapper",
19
-
"name": "lazy"
22
+
"name": "lazy"
20
23
}]
21
24
}]
22
25
```
23
26
27
+
### Custom signatures without package source (matches any import)
28
+
29
+
To match any import with a specific name regardless of the source package (useful for vendored or aliased packages), omit the `from` field:
30
+
31
+
```json
32
+
["loadable-components", { "signatures": [
33
+
{
34
+
"name": "loadable"
35
+
}]
36
+
}]
37
+
```
38
+
39
+
This will transform any default import named `loadable`, regardless of where it's imported from:
40
+
```js
41
+
importloadablefrom'my-vendored-loadable'; // will be transformed
42
+
importloadablefrom'@loadable/component'; // will be transformed
0 commit comments