@pit-frontend-framework/unplugin-vue-components 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-PRESENT Anthony Fu<https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,464 @@
1
+ # unplugin-vue-components
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/unplugin-vue-components?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-vue-components)
4
+
5
+ On-demand components auto importing for Vue.
6
+
7
+ ###### Features
8
+
9
+ - 💚 Supports Vue 3 out-of-the-box.
10
+ - ✨ Supports both components and directives.
11
+ - ⚡️ Supports Vite, Webpack, Rspack, Rollup, Rolldown, esbuild and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a>.
12
+ - 🏝 Tree-shakable, only registers the components you use.
13
+ - 🪐 Folder names as namespaces.
14
+ - 🦾 Full TypeScript support.
15
+ - 🌈 [Built-in resolvers](#importing-from-ui-libraries) for popular UI libraries.
16
+ - 😃 Works perfectly with [unplugin-icons](https://github.com/antfu/unplugin-icons).
17
+
18
+ <br>
19
+
20
+ <p align="center">
21
+ <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
22
+ <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt='Sponsors'/>
23
+ </a>
24
+ </p>
25
+
26
+ <br>
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm i unplugin-vue-components -D
32
+ ```
33
+
34
+ > **`vite-plugin-components` has been renamed to `unplugin-vue-components`**, see the [migration guide](#migrate-from-vite-plugin-components).
35
+
36
+ <details>
37
+ <summary>Vite</summary><br>
38
+
39
+ ```ts
40
+ // vite.config.ts
41
+ import Components from 'unplugin-vue-components/vite'
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ Components({ /* options */ }),
46
+ ],
47
+ })
48
+ ```
49
+
50
+ <br></details>
51
+
52
+ <details>
53
+ <summary>Rollup</summary><br>
54
+
55
+ ```ts
56
+ // rollup.config.js
57
+ import Components from 'unplugin-vue-components/rollup'
58
+
59
+ export default {
60
+ plugins: [
61
+ Components({ /* options */ }),
62
+ ],
63
+ }
64
+ ```
65
+
66
+ <br></details>
67
+
68
+ <details>
69
+ <summary>Rolldown</summary><br>
70
+
71
+ ```ts
72
+ // rolldown.config.js
73
+ import Components from 'unplugin-vue-components/rolldown'
74
+
75
+ export default {
76
+ plugins: [
77
+ Components({ /* options */ }),
78
+ ],
79
+ }
80
+ ```
81
+
82
+ <br></details>
83
+
84
+ <details>
85
+ <summary>Webpack</summary><br>
86
+
87
+ ```ts
88
+ // webpack.config.js
89
+ // unplugin-vue-components removed support for CommonJS after version 29.1.0
90
+ module.exports = {
91
+ /* ... */
92
+ plugins: [
93
+ require('unplugin-vue-components/webpack')({ /* options */ }),
94
+ ],
95
+ }
96
+ ```
97
+
98
+ <br></details>
99
+
100
+ <details>
101
+ <summary>Rspack</summary><br>
102
+
103
+ ```ts
104
+ // rspack.config.js
105
+ // unplugin-vue-components removed support for CommonJS after version 29.1.0
106
+ module.exports = {
107
+ /* ... */
108
+ plugins: [
109
+ require('unplugin-vue-components/rspack')({ /* options */ }),
110
+ ],
111
+ }
112
+ ```
113
+
114
+ <br></details>
115
+
116
+ <details>
117
+ <summary>Nuxt</summary><br>
118
+
119
+ You might not need this plugin for Nuxt. Use [`@nuxt/components`](https://github.com/nuxt/components) instead.
120
+
121
+ <br></details>
122
+
123
+ <details>
124
+ <summary>Quasar</summary><br>
125
+
126
+ ```ts
127
+ // vite.config.js [Vite]
128
+ import Components from 'unplugin-vue-components/vite'
129
+ import { defineConfig } from 'vite'
130
+
131
+ export default defineConfig({
132
+ plugins: [
133
+ Components({ /* options */ })
134
+ ]
135
+ })
136
+ ```
137
+
138
+ ```ts
139
+ // quasar.config.js
140
+ export default defineConfig(() => {
141
+ return {
142
+ build: {
143
+ vitePlugins: [
144
+ ['unplugin-vue-components/vite', { /* options */ }],
145
+ ]
146
+ },
147
+ }
148
+ })
149
+ ```
150
+
151
+ <br></details>
152
+
153
+ <details>
154
+ <summary>esbuild</summary><br>
155
+
156
+ ```ts
157
+ // esbuild.config.js
158
+ import { build } from 'esbuild'
159
+ import Components from 'unplugin-vue-components/esbuild'
160
+
161
+ build({
162
+ /* ... */
163
+ plugins: [
164
+ Components({
165
+ /* options */
166
+ }),
167
+ ],
168
+ })
169
+ ```
170
+
171
+ <br></details>
172
+
173
+ ## Usage
174
+
175
+ Use components in templates as you would usually do, it will import components on demand, and there is no `import` and `component registration` required anymore! If you register the parent component asynchronously (or lazy route), the auto-imported components will be code-split along with their parent.
176
+
177
+ It will automatically turn this
178
+
179
+ ```html
180
+ <template>
181
+ <div>
182
+ <HelloWorld msg="Hello Vue 3.0 + Vite" />
183
+ </div>
184
+ </template>
185
+
186
+ <script>
187
+ export default {
188
+ name: 'App',
189
+ }
190
+ </script>
191
+ ```
192
+
193
+ into this
194
+
195
+ ```html
196
+ <template>
197
+ <div>
198
+ <HelloWorld msg="Hello Vue 3.0 + Vite" />
199
+ </div>
200
+ </template>
201
+
202
+ <script>
203
+ import HelloWorld from './src/components/HelloWorld.vue'
204
+
205
+ export default {
206
+ name: 'App',
207
+ components: {
208
+ HelloWorld,
209
+ },
210
+ }
211
+ </script>
212
+ ```
213
+
214
+ > **Note**
215
+ > By default this plugin will import components in the `src/components` path. You can customize it using the `dirs` option.
216
+
217
+ ## TypeScript
218
+
219
+ To get TypeScript support for auto-imported components, there is [a PR](https://github.com/vuejs/core/pull/3399) to Vue 3 extending the interface of global components. Currently, [Volar](https://github.com/johnsoncodehk/volar) has supported this usage already. If you are using Volar, you can change the config as following to get the support.
220
+
221
+ ```ts
222
+ Components({
223
+ dts: true, // enabled by default if `typescript` is installed
224
+ })
225
+ ```
226
+
227
+ Once the setup is done, a `components.d.ts` will be generated and updates automatically with the type definitions. Feel free to commit it into git or not as you want.
228
+
229
+ > **Make sure you also add `components.d.ts` to your `tsconfig.json` under `include`.**
230
+
231
+ ## Importing from UI Libraries
232
+
233
+ We have several built-in resolvers for popular UI libraries like **Vuetify**, **Ant Design Vue**, and **Element Plus**, where you can enable them by:
234
+
235
+ Supported Resolvers:
236
+
237
+ - [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
238
+ - [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
239
+ - [BootstrapVue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/bootstrap-vue.ts)
240
+ - [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
241
+ - [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
242
+ - [IDux](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/idux.ts)
243
+ - [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)
244
+ - [Ionic](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/ionic.ts)
245
+ - [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
246
+ - [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
247
+ - [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
248
+ - [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
249
+ - [`@tdesign-vue-next/auto-import-resolver`](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/auto-import-resolver/README.md) - TDesign's own auto-import resolver
250
+ - [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
251
+ - [`@vant/auto-import-resolver`](https://github.com/youzan/vant/blob/main/packages/vant-auto-import-resolver/README.md) - Vant's own auto-import resolver
252
+ - [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
253
+ - [`@varlet/import-resolver`](https://github.com/varletjs/varlet/blob/dev/packages/varlet-import-resolver/README.md) - Varlet's own auto-import resolver
254
+ - [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
255
+ - [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
256
+ - [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts) &mdash; Prefer first-party plugins when possible: [v3 + vite](https://www.npmjs.com/package/vite-plugin-vuetify), [v3 + webpack](https://www.npmjs.com/package/webpack-plugin-vuetify), [v2 + webpack](https://npmjs.com/package/vuetify-loader)
257
+ - [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
258
+ - [VueUse Directives](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse-directive.ts)
259
+ - [Dev UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts)
260
+
261
+ ```ts
262
+ import {
263
+ AntDesignVueResolver,
264
+ ElementPlusResolver,
265
+ VantResolver,
266
+ } from 'unplugin-vue-components/resolvers'
267
+ // vite.config.js
268
+ import Components from 'unplugin-vue-components/vite'
269
+
270
+ // your plugin installation
271
+ Components({
272
+ resolvers: [
273
+ AntDesignVueResolver(),
274
+ ElementPlusResolver(),
275
+ VantResolver(),
276
+ ],
277
+ })
278
+ ```
279
+
280
+ You can also write your own resolver quickly:
281
+
282
+ ```ts
283
+ Components({
284
+ resolvers: [
285
+ // example of importing Vant
286
+ (componentName) => {
287
+ // where `componentName` is always CapitalCase
288
+ if (componentName.startsWith('Van'))
289
+ return { name: componentName.slice(3), from: 'vant' }
290
+ },
291
+ ],
292
+ })
293
+ ```
294
+
295
+ > [We no longer accept new resolvers](./src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md).
296
+
297
+ ## Types for global registered components
298
+
299
+ Some libraries might register some global components for you to use anywhere (e.g. Vue Router provides `<RouterLink>` and `<RouterView>`). Since they are global available, there is no need for this plugin to import them. However, those are commonly not TypeScript friendly, and you might need to register their types manually.
300
+
301
+ Thus `unplugin-vue-components` provided a way to only register types for global components.
302
+
303
+ ```ts
304
+ Components({
305
+ dts: true,
306
+ types: [{
307
+ from: 'vue-router',
308
+ names: ['RouterLink', 'RouterView'],
309
+ }],
310
+ })
311
+ ```
312
+
313
+ So the `RouterLink` and `RouterView` will be presented in `components.d.ts`.
314
+
315
+ By default, `unplugin-vue-components` detects supported libraries automatically (e.g. `vue-router`) when they are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:
316
+
317
+ ```ts
318
+ Components({
319
+ // Disable type only registration
320
+ types: [],
321
+ })
322
+ ```
323
+
324
+ ## Migrate from `vite-plugin-components`
325
+
326
+ `package.json`
327
+
328
+ ```diff
329
+ {
330
+ "devDependencies": {
331
+ - "vite-plugin-components": "*",
332
+ + "unplugin-vue-components": "^0.14.0",
333
+ }
334
+ }
335
+ ```
336
+
337
+ `vite.config.js`
338
+
339
+ ```diff
340
+ - import Components, { ElementPlusResolver } from 'vite-plugin-components'
341
+ + import Components from 'unplugin-vue-components/vite'
342
+ + import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
343
+
344
+ export default {
345
+ plugins: [
346
+ /* ... */
347
+ Components({
348
+ /* ... */
349
+
350
+ // `customComponentsResolvers` has renamed to `resolver`
351
+ - customComponentsResolvers: [
352
+ + resolvers: [
353
+ ElementPlusResolver(),
354
+ ],
355
+
356
+ // `globalComponentsDeclaration` has renamed to `dts`
357
+ - globalComponentsDeclaration: true,
358
+ + dts: true,
359
+
360
+ // `customLoaderMatcher` is depreacted, use `include` instead
361
+ - customLoaderMatcher: id => id.endsWith('.md'),
362
+ + include: [/\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.md$/],
363
+ }),
364
+ ],
365
+ }
366
+ ```
367
+
368
+ ## Configuration
369
+
370
+ The following show the default values of the configuration
371
+
372
+ ```ts
373
+ Components({
374
+ // relative paths to the directory to search for components.
375
+ dirs: ['src/components'],
376
+
377
+ // valid file extensions for components.
378
+ extensions: ['vue'],
379
+
380
+ // Glob patterns to match file names to be detected as components.
381
+ // You can also specify multiple like this: `src/components/*.{vue,tsx}`
382
+ // When specified, the `dirs`, `extensions`, and `directoryAsNamespace` options will be ignored.
383
+ // If you want to exclude components being registered, use negative globs with leading `!`.
384
+ globs: ['src/components/*.vue'],
385
+
386
+ // search for subdirectories
387
+ deep: true,
388
+
389
+ // resolvers for custom components
390
+ resolvers: [],
391
+
392
+ // generate `components.d.ts` global declarations,
393
+ // also accepts a path for custom filename
394
+ // default: `true` if package typescript is installed
395
+ dts: false,
396
+
397
+ // generate dts with TSX support
398
+ // default: `true` if `@vitejs/plugin-vue-jsx` is installed
399
+ dtsTsx: false,
400
+
401
+ // Allow subdirectories as namespace prefix for components.
402
+ directoryAsNamespace: false,
403
+
404
+ // Collapse same prefixes (camel-sensitive) of folders and components
405
+ // to prevent duplication inside namespaced component name.
406
+ // works when `directoryAsNamespace: true`
407
+ collapseSamePrefixes: false,
408
+
409
+ // Subdirectory paths for ignoring namespace prefixes.
410
+ // works when `directoryAsNamespace: true`
411
+ globalNamespaces: [],
412
+
413
+ // auto import for directives
414
+ directives: true,
415
+
416
+ // Transform path before resolving
417
+ importPathTransform: v => v,
418
+
419
+ // Allow for components to override other components with the same name
420
+ allowOverrides: false,
421
+
422
+ // Filters for transforming targets (components to insert the auto import)
423
+ // Note these are NOT about including/excluding components registered - use `globs` or `excludeNames` for that
424
+ include: [/\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/],
425
+ exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
426
+
427
+ // Filters for component names that will not be imported
428
+ // Use for globally imported async components or other conflicts that the plugin cannot detect
429
+ excludeNames: [/^Async.+/],
430
+
431
+ // Vue version of project. It will detect automatically if not specified.
432
+ // Acceptable value: 2 | 2.7 | 3
433
+ version: 2.7,
434
+
435
+ // Only provide types of components in library (registered globally)
436
+ // see https://github.com/unplugin/unplugin-vue-components/blob/main/src/core/type-imports/index.ts
437
+ types: [
438
+ /* ... */
439
+ ],
440
+
441
+ // Save component information into a JSON file for other tools to consume.
442
+ // Provide a filepath to save the JSON file.
443
+ // When set to `true`, it will save to `./.components-info.json`
444
+ dumpComponentsInfo: false,
445
+
446
+ // The mode for syncing the components.d.ts and .components-info.json file.
447
+ // 'append': only append the new components to the existing files.
448
+ // 'overwrite': overwrite the whole existing files with the current components.
449
+ // 'default': use 'append' strategy when using dev server, 'overwrite' strategy when using build.
450
+ syncMode: 'default',
451
+ })
452
+ ```
453
+
454
+ ## Example
455
+
456
+ [Vitesse](https://github.com/antfu/vitesse) starter template.
457
+
458
+ ## Thanks
459
+
460
+ Thanks to [@brattonross](https://github.com/brattonross), this project is heavily inspired by [vite-plugin-voie](https://github.com/vamplate/vite-plugin-voie).
461
+
462
+ ## License
463
+
464
+ [MIT](./LICENSE) License © 2020-PRESENT [Anthony Fu](https://github.com/antfu)
@@ -0,0 +1,6 @@
1
+ import { u as Options } from "./types-BbnOeCab.mjs";
2
+
3
+ //#region src/esbuild.d.ts
4
+ declare const esbuild: (options: Options) => EsbuildPlugin;
5
+ //#endregion
6
+ export { esbuild as default, esbuild as "module.exports" };
@@ -0,0 +1,5 @@
1
+ import { t as unplugin_default } from "./src-S1kwY0Q8.mjs";
2
+ //#region src/esbuild.ts
3
+ const esbuild = unplugin_default.esbuild;
4
+ //#endregion
5
+ export { esbuild as default, esbuild as "module.exports" };
@@ -0,0 +1,11 @@
1
+ import { a as ComponentResolverObject, c as ImportInfoLegacy, d as PublicPluginAPI, f as ResolvedOptions, h as TypeImport, i as ComponentResolverFunction, l as Matcher, m as Transformer, n as ComponentResolveResult, o as ComponentsImportMap, p as SideEffectsInfo, r as ComponentResolver, s as ImportInfo, t as ComponentInfo, u as Options } from "./types-BbnOeCab.mjs";
2
+ import { FilterPattern } from "unplugin-utils";
3
+ //#region src/core/unplugin.d.ts
4
+ declare const _default: import("unplugin").UnpluginInstance<Options, boolean>;
5
+ //#endregion
6
+ //#region src/core/utils.d.ts
7
+ declare function pascalCase(str: string): string;
8
+ declare function camelCase(str: string): string;
9
+ declare function kebabCase(key: string): string;
10
+ //#endregion
11
+ export { ComponentInfo, ComponentResolveResult, ComponentResolver, ComponentResolverFunction, ComponentResolverObject, ComponentsImportMap, ImportInfo, ImportInfoLegacy, Matcher, Options, PublicPluginAPI, ResolvedOptions, SideEffectsInfo, Transformer, TypeImport, camelCase, _default as default, kebabCase, pascalCase };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { c as kebabCase, f as pascalCase, t as camelCase } from "./utils-BfjsfvcK.mjs";
2
+ import { t as unplugin_default } from "./src-S1kwY0Q8.mjs";
3
+ export { camelCase, unplugin_default as default, kebabCase, pascalCase };
@@ -0,0 +1,7 @@
1
+ import { u as Options } from "./types-BbnOeCab.mjs";
2
+ import { NuxtModule } from "@nuxt/schema";
3
+
4
+ //#region src/nuxt.d.ts
5
+ declare const module: NuxtModule<Options, Options, false>;
6
+ //#endregion
7
+ export { module as default };
package/dist/nuxt.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import { t as unplugin_default } from "./src-S1kwY0Q8.mjs";
2
+ import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
3
+ //#region src/nuxt.ts
4
+ const module = defineNuxtModule({ setup(options) {
5
+ addWebpackPlugin(unplugin_default.webpack(options));
6
+ addVitePlugin(unplugin_default.vite(options));
7
+ } });
8
+ //#endregion
9
+ export { module as default };