swc-plugin-auto-import 0.0.0 → 0.0.2
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
|
@@ -32,11 +32,17 @@ pnpm add swc-plugin-auto-import
|
|
|
32
32
|
[
|
|
33
33
|
"swc-plugin-auto-import",
|
|
34
34
|
{
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
"imports": [
|
|
36
|
+
"vue",
|
|
37
|
+
"react",
|
|
38
|
+
{
|
|
39
|
+
"@vueuse/core": ["useMouse", "useFetch"]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"from": "axios",
|
|
43
|
+
"imports": [["default", "axios"]]
|
|
44
|
+
}
|
|
45
|
+
],
|
|
40
46
|
"debug": false
|
|
41
47
|
}
|
|
42
48
|
]
|
|
@@ -56,10 +62,12 @@ module.exports = {
|
|
|
56
62
|
[
|
|
57
63
|
'swc-plugin-auto-import',
|
|
58
64
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
imports: [
|
|
66
|
+
'react',
|
|
67
|
+
{
|
|
68
|
+
'lodash-es': ['debounce', 'throttle'],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
63
71
|
},
|
|
64
72
|
],
|
|
65
73
|
],
|
|
@@ -84,7 +92,7 @@ module.exports = {
|
|
|
84
92
|
[
|
|
85
93
|
'swc-plugin-auto-import',
|
|
86
94
|
{
|
|
87
|
-
|
|
95
|
+
imports: ['react'],
|
|
88
96
|
},
|
|
89
97
|
],
|
|
90
98
|
],
|
|
@@ -105,7 +113,7 @@ module.exports = {
|
|
|
105
113
|
|
|
106
114
|
```json
|
|
107
115
|
{
|
|
108
|
-
"
|
|
116
|
+
"imports": ["vue"]
|
|
109
117
|
}
|
|
110
118
|
```
|
|
111
119
|
|
|
@@ -139,7 +147,7 @@ onMounted(() => {
|
|
|
139
147
|
|
|
140
148
|
```json
|
|
141
149
|
{
|
|
142
|
-
"
|
|
150
|
+
"imports": ["react"]
|
|
143
151
|
}
|
|
144
152
|
```
|
|
145
153
|
|
|
@@ -171,11 +179,18 @@ useEffect(() => {
|
|
|
171
179
|
|
|
172
180
|
```json
|
|
173
181
|
{
|
|
174
|
-
"imports":
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
"imports": [
|
|
183
|
+
{
|
|
184
|
+
"@vueuse/core": ["useMouse", "useKeyboard"]
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"lodash-es": ["debounce", "throttle"]
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"from": "axios",
|
|
191
|
+
"imports": [["default", "axios"]]
|
|
192
|
+
}
|
|
193
|
+
]
|
|
179
194
|
}
|
|
180
195
|
```
|
|
181
196
|
|
|
@@ -203,30 +218,66 @@ axios.get('/api/data')
|
|
|
203
218
|
|
|
204
219
|
## ⚙️ Configuration Options
|
|
205
220
|
|
|
206
|
-
### `
|
|
221
|
+
### `imports`
|
|
207
222
|
|
|
208
|
-
**Type:** `string
|
|
223
|
+
**Type:** `Array<string | object>`
|
|
209
224
|
**Default:** `[]`
|
|
210
225
|
|
|
211
|
-
|
|
226
|
+
Import configuration. Supports three formats:
|
|
227
|
+
|
|
228
|
+
#### 1. Preset String (Built-in presets)
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"imports": ["vue", "react", "vue-router", "react-router"]
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Currently supported presets:
|
|
212
237
|
|
|
213
238
|
- `"vue"` - Vue 3 Composition API
|
|
214
239
|
- `"react"` - React Hooks
|
|
240
|
+
- `"react-dom"` - React DOM APIs
|
|
215
241
|
- `"vue-router"` - Vue Router Composition API
|
|
216
242
|
- `"react-router"` - React Router Hooks
|
|
217
243
|
|
|
218
|
-
|
|
244
|
+
#### 2. Package Mapping Object
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"imports": [
|
|
249
|
+
{
|
|
250
|
+
"package-name": ["namedExport1", "namedExport2"]
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
```
|
|
219
255
|
|
|
220
|
-
**
|
|
221
|
-
**Default:** `{}`
|
|
256
|
+
**Example:**
|
|
222
257
|
|
|
223
|
-
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"imports": [
|
|
261
|
+
{
|
|
262
|
+
"@vueuse/core": ["useMouse", "useFetch"]
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"date-fns": ["format", "parseISO"]
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
```
|
|
224
270
|
|
|
225
|
-
|
|
271
|
+
#### 3. Explicit Import Object
|
|
226
272
|
|
|
227
273
|
```json
|
|
228
274
|
{
|
|
229
|
-
"
|
|
275
|
+
"imports": [
|
|
276
|
+
{
|
|
277
|
+
"from": "package-name",
|
|
278
|
+
"imports": ["export1", ["exportName", "alias"]]
|
|
279
|
+
}
|
|
280
|
+
]
|
|
230
281
|
}
|
|
231
282
|
```
|
|
232
283
|
|
|
@@ -234,9 +285,36 @@ Custom import configuration.
|
|
|
234
285
|
|
|
235
286
|
```json
|
|
236
287
|
{
|
|
237
|
-
"
|
|
238
|
-
|
|
239
|
-
|
|
288
|
+
"imports": [
|
|
289
|
+
{
|
|
290
|
+
"from": "axios",
|
|
291
|
+
"imports": [["default", "axios"]]
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"from": "motion/react-m",
|
|
295
|
+
"imports": [["*", "motion"]]
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### Mixed Format
|
|
302
|
+
|
|
303
|
+
You can combine all three formats:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"imports": [
|
|
308
|
+
"react",
|
|
309
|
+
"react-dom",
|
|
310
|
+
{
|
|
311
|
+
"@vueuse/core": ["useMouse", "useFetch"]
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
"from": "axios",
|
|
315
|
+
"imports": [["default", "axios"]]
|
|
316
|
+
}
|
|
317
|
+
]
|
|
240
318
|
}
|
|
241
319
|
```
|
|
242
320
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swc-plugin-auto-import",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "SWC plugin for auto importing APIs on-demand, inspired by unplugin-auto-import",
|
|
6
6
|
"author": "Brendan Dash <me@aiwan.run> (https://aiwan.run)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"build": "cargo build-wasip1 --release",
|
|
34
34
|
"test": "cargo test",
|
|
35
35
|
"release": "pnpm build && bumpp && pnpm publish",
|
|
36
|
+
"typecheck": "echo 'No typechecking for wasm plugins'",
|
|
36
37
|
"lint": "eslint",
|
|
37
38
|
"lint:fix": "eslint --fix"
|
|
38
39
|
}
|
|
Binary file
|