swc-plugin-add-display-name 0.1.2 → 0.2.0

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,6 +1,9 @@
1
1
  # swc-plugin-add-display-name
2
2
 
3
3
  Automatically add `displayName` to *top-level* React *functional* components.
4
+ - ✅ `const Component = () => <jsx />`
5
+ - ✅ `function Component() { return <jsx /> }`
6
+ - ❌ `const Context = createContext()`
4
7
 
5
8
  > If you have other situations that needs to add `displayName`, feel free to open an issue or PR!
6
9
 
@@ -47,7 +50,38 @@ Add plugin to wherever you have an SWC config (e.g. `.swcrc` file, `swc-loader`
47
50
 
48
51
  ## Configuration
49
52
 
50
- The plugin currently has no configuration. However you have to leave an empty object to meet SWC's API schema.
53
+ This plugin currently has no configuration. However you have to leave an empty object to meet SWC's API schema.
54
+
55
+ If you'd like to disable this plugin in production build, remove this plugin from the plugins list.
56
+
57
+ ## Examples
58
+
59
+ ```tsx
60
+ // Before
61
+ export const Component = () => <div />;
62
+
63
+ // After
64
+ export const Component = () => <div />;
65
+ Component.displayName = "Component";
66
+ ```
67
+
68
+ ```tsx
69
+ // Before
70
+ const Component = forwardRef((props, ref) => <div />);
71
+
72
+ // After
73
+ const Component = forwardRef((props, ref) => <div />);
74
+ Component.displayName = "Component";
75
+ ```
76
+
77
+ ```tsx
78
+ // Before
79
+ export function Component() { return <div />; }
80
+
81
+ // After
82
+ export function Component() { return <div />; }
83
+ Component.displayName = "Component";
84
+ ```
51
85
 
52
86
  ## License
53
87
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swc-plugin-add-display-name",
3
- "version": "0.1.2",
4
- "description": "Automatically add displayName to React functional components via SWC.",
3
+ "version": "0.2.0",
4
+ "description": "An SWC plugin to add displayName to React components",
5
5
  "author": "hjkcai <huajingkun1214@gmail.com>",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -15,6 +15,9 @@
15
15
  "scripts": {
16
16
  "prepublishOnly": "cargo build-wasi --release"
17
17
  },
18
+ "peerDependencies": {
19
+ "@swc/core": "^1.3.58"
20
+ },
18
21
  "devDependencies": {
19
22
  "@swc/cli": "^0.1.59",
20
23
  "@swc/core": "^1.3.26"