swc-plugin-add-display-name 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# swc-plugin-add-display-name
|
|
2
2
|
|
|
3
|
+
> **PLEASE GIVE A STAR IF YOU LIKE THIS PROJECT!**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
3
8
|
Automatically add `displayName` to *top-level* React *functional* components:
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
9
|
+
- `const Component = () => <jsx />`
|
|
10
|
+
- `function Component() { return <jsx /> }`
|
|
11
|
+
- `const Component = () => jsx("div", { children: "hello" })` (Compiled JSX code)
|
|
12
|
+
- `const Component = () => React.createElement("div", null, "hello")` (Compiled or hand-written JSX code)
|
|
8
13
|
|
|
9
14
|
And some API calls that produce component:
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
And even compiled code!
|
|
15
|
+
- `const Context = createContext()` (React Context)
|
|
16
|
+
- `const StyledButton = styled.button` (Styled Components)
|
|
17
|
+
- `const ObservedComponent = observer(() => <jsx />)` (MobX observer)
|
|
18
|
+
- `const ConnectedComponent = connect(...)(() => <jsx />)` (Redux connect)
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
If you have other situations that needs to add `displayName`, feel free to open an issue or PR!
|
|
18
21
|
|
|
19
22
|
## Installation
|
|
20
23
|
|
|
@@ -24,44 +27,64 @@ Install with your favorite package manager as devDependency.
|
|
|
24
27
|
npm i -D swc-plugin-add-display-name
|
|
25
28
|
```
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
## Configuration
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
Add this plugin to wherever you have an SWC config.
|
|
33
|
+
|
|
34
|
+
This plugin currently has no configuration. However you have to pass an empty object to meet SWC's API schema.
|
|
35
|
+
|
|
36
|
+
If you'd like to disable this plugin in production build, remove this plugin from the plugins list.
|
|
37
|
+
|
|
38
|
+
### [`.swcrc`](https://swc.rs/docs/configuration/compilation#jscexperimentalplugins)
|
|
39
|
+
|
|
40
|
+
You may configure SWC directly via `.swcrc`.
|
|
41
|
+
Or pass the configuration as options to loaders (e.g. `swc-loader`, Rspack's `builtin:swc-loader`).
|
|
42
|
+
|
|
43
|
+
Make sure either `jsx` or `tsx` option is turned on depending on the syntax you are using.
|
|
44
|
+
|
|
45
|
+
```json
|
|
31
46
|
{
|
|
32
|
-
jsc: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
47
|
+
"jsc": {
|
|
48
|
+
"experimental": {
|
|
49
|
+
"plugins": [
|
|
50
|
+
["swc-plugin-add-display-name", {}]
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
42
54
|
}
|
|
55
|
+
```
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
### [Rsbuild](https://rsbuild.rs/guide/configuration/swc#register-swc-plugin)
|
|
58
|
+
|
|
59
|
+
Simply configure SWC via `tools.swc`.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
export default {
|
|
63
|
+
tools: {
|
|
64
|
+
swc: {
|
|
65
|
+
jsc: {
|
|
66
|
+
experimental: {
|
|
67
|
+
plugins: [
|
|
68
|
+
['swc-plugin-add-display-name', {}],
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
50
72
|
},
|
|
51
|
-
experimental: {
|
|
52
|
-
plugins: [
|
|
53
|
-
['swc-plugin-add-display-name', {}],
|
|
54
|
-
],
|
|
55
|
-
}
|
|
56
73
|
},
|
|
57
|
-
}
|
|
74
|
+
};
|
|
58
75
|
```
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
### [Next.js](https://nextjs.org/docs/architecture/nextjs-compiler)
|
|
61
78
|
|
|
62
|
-
|
|
79
|
+
If you’re using the Next.js Compiler powered by SWC, add this plugin to your next.config.js.
|
|
63
80
|
|
|
64
|
-
|
|
81
|
+
```js
|
|
82
|
+
module.exports = {
|
|
83
|
+
experimental: {
|
|
84
|
+
swcPlugins: [['swc-plugin-add-display-name', {}]],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
```
|
|
65
88
|
|
|
66
89
|
## Examples
|
|
67
90
|
|
|
@@ -149,6 +172,32 @@ export const ConnectedComponent = connect(() => ({}))(() => null);
|
|
|
149
172
|
ConnectedComponent.displayName = "ConnectedComponent";
|
|
150
173
|
```
|
|
151
174
|
|
|
175
|
+
## Troubleshooting
|
|
176
|
+
|
|
177
|
+
### SWC Versions
|
|
178
|
+
|
|
179
|
+
SWC plugins may encounter compatibility issues across different SWC versions.
|
|
180
|
+
If your app won't compile after configuring this plugin,
|
|
181
|
+
please try to find a compatible version between this plugin and SWC.
|
|
182
|
+
|
|
183
|
+
You may refer to the following docs:
|
|
184
|
+
- [Selecting the version](https://swc.rs/docs/plugin/selecting-swc-core)
|
|
185
|
+
- [SWC compatibility table](https://plugins.swc.rs/versions/range)
|
|
186
|
+
- [SWC plugin version mismatch](https://rspack.rs/errors/swc-plugin-version)
|
|
187
|
+
|
|
188
|
+
| swc-plugin-add-display-name | swc_core |
|
|
189
|
+
|-----------------------------|----------|
|
|
190
|
+
| >0.9.0 | 54.0.0 |
|
|
191
|
+
| >=0.7.0 <0.9.0 | 46.0.3 |
|
|
192
|
+
| ^0.6.0 | 31.1.0 |
|
|
193
|
+
|
|
194
|
+
### Incorrect Results
|
|
195
|
+
|
|
196
|
+
Please file an issue if this plugin:
|
|
197
|
+
- Causes runtime errors (e.g. `Cannot add property displayName, object is not extensible`, `Cannot create property 'displayName'`).
|
|
198
|
+
- Adds `displayName` where it shouldn't.
|
|
199
|
+
- Fails to add `displayName` on certain cases.
|
|
200
|
+
|
|
152
201
|
## License
|
|
153
202
|
|
|
154
203
|
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swc-plugin-add-display-name",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.9.3",
|
|
4
|
+
"description": "Automatically add displayName to top-level React functional components",
|
|
5
5
|
"author": "hjkcai <huajingkun1214@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -15,9 +15,6 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"prepublishOnly": "cargo build-wasi --release"
|
|
17
17
|
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"@swc/core": "^1.15.0"
|
|
20
|
-
},
|
|
21
18
|
"devDependencies": {
|
|
22
19
|
"@swc/cli": "^0.6.0",
|
|
23
20
|
"@swc/core": "^1.15.0"
|
|
Binary file
|