unplugin-vue-components 0.19.5 → 0.19.6

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
@@ -176,7 +176,7 @@ Components({
176
176
 
177
177
  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.
178
178
 
179
- **Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
179
+ > **Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
180
180
 
181
181
  ## Importing from UI Libraries
182
182
 
@@ -256,7 +256,7 @@ Components({
256
256
 
257
257
  So the `RouterLink` and `RouterView` will be presented in `components.d.ts`.
258
258
 
259
- By default, `unplugin-vue-components` detects supported libraries automatically (e.g. `vue-router`) when their are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:
259
+ 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:
260
260
 
261
261
  ```ts
262
262
  Components({
@@ -342,6 +342,12 @@ Components({
342
342
  // To install Babel, run: `npm install -D @babel/parser @babel/traverse`
343
343
  directives: true,
344
344
 
345
+ // Transform path before resolving
346
+ importPathTransform: v => v,
347
+
348
+ // Allow for components to override other components with the same name
349
+ allowOverrides: false,
350
+
345
351
  // filters for transforming targets
346
352
  include: [/\.vue$/, /\.vue\?vue/],
347
353
  exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
@@ -350,7 +356,7 @@ Components({
350
356
 
351
357
  ## Example
352
358
 
353
- See the [Vitesse](https://github.com/antfu/vitesse) starter template.
359
+ [Vitesse](https://github.com/antfu/vitesse) starter template.
354
360
 
355
361
  ## Thanks
356
362
 
@@ -131,6 +131,12 @@ interface IduxResolverOptions {
131
131
  * import style along with components
132
132
  */
133
133
  importStyle?: 'css' | 'less';
134
+ /**
135
+ * theme for import style
136
+ *
137
+ * @default 'default'
138
+ */
139
+ importStyleTheme?: string;
134
140
  }
135
141
  /**
136
142
  * Resolver for `@idux/cdk`, `@idux/components` and ``@idux/pro``
@@ -291,7 +297,7 @@ interface VeuiResolverOptions {
291
297
  *
292
298
  * @link https://github.com/ecomfe/veui
293
299
  */
294
- declare function VeuiResolver(options: VeuiResolverOptions): ComponentResolver;
300
+ declare function VeuiResolver(options?: VeuiResolverOptions): ComponentResolver;
295
301
 
296
302
  /**
297
303
  * Resolver for View UI
package/dist/resolvers.js CHANGED
@@ -389,7 +389,7 @@ function ElementPlusResolver(options = {}) {
389
389
  return optionsResolved;
390
390
  optionsResolved = _chunkTMX2H7L5js.__spreadValues.call(void 0, {
391
391
  ssr: false,
392
- version: await _chunkTMX2H7L5js.getPkgVersion.call(void 0, "element-plus", "1.1.0-beta.21"),
392
+ version: await _chunkTMX2H7L5js.getPkgVersion.call(void 0, "element-plus", "2.2.2"),
393
393
  importStyle: "css",
394
394
  directives: true,
395
395
  exclude: void 0
@@ -523,18 +523,20 @@ var specialComponents = {
523
523
  IxAutoComplete: "auto-complete",
524
524
  IxBackTop: "back-top",
525
525
  IxDatePicker: "date-picker",
526
+ IxDateRangePicker: "date-picker",
526
527
  IxCol: "grid",
527
528
  IxRow: "grid",
528
529
  IxInputNumber: "input-number",
529
530
  IxTab: "tabs",
530
531
  IxTreeSelect: "tree-select",
531
- IxTimePicker: "time-picker"
532
+ IxTimePicker: "time-picker",
533
+ IxTimeRangePicker: "time-picker"
532
534
  };
533
535
  function IduxResolver(options = {}) {
534
536
  return {
535
537
  type: "component",
536
538
  resolve: (name) => {
537
- const { importStyle, exclude = [] } = options;
539
+ const { importStyle, importStyleTheme = "default", exclude = [] } = options;
538
540
  if (exclude.includes(name))
539
541
  return;
540
542
  const packageName = getPackageName(name);
@@ -548,7 +550,7 @@ function IduxResolver(options = {}) {
548
550
  const path = `@idux/${packageName}/${dirname}`;
549
551
  let sideEffects;
550
552
  if (packageName !== "cdk" && importStyle)
551
- sideEffects = `${path}/style/themes/${importStyle === "css" ? "default_css" : "default"}`;
553
+ sideEffects = `${path}/style/themes/${importStyle === "css" ? `${importStyleTheme}_css` : importStyleTheme}`;
552
554
  return { name, from: path, sideEffects };
553
555
  }
554
556
  };
@@ -786,7 +788,7 @@ function VarletUIResolver(options = {}) {
786
788
  var _path = require('path');
787
789
  var VEUI_PACKAGE_NAME = "veui";
788
790
  var components3;
789
- function VeuiResolver(options) {
791
+ function VeuiResolver(options = {}) {
790
792
  const { alias = VEUI_PACKAGE_NAME } = options;
791
793
  if (!components3) {
792
794
  try {
@@ -1298,13 +1300,16 @@ var layuiRE = /^Lay[A-Z]/;
1298
1300
  var layerRE = /^(layer|LayLayer)$/;
1299
1301
  var iconsRE = /^([A-Z][\w]+Icon|LayIcon)$/;
1300
1302
  var libName = "@layui/layui-vue";
1303
+ function lowerCamelCase(str) {
1304
+ return str.charAt(0).toLowerCase() + str.slice(1);
1305
+ }
1301
1306
  function getSideEffects9(importName, options) {
1302
1307
  const { importStyle = "css" } = options;
1303
1308
  if (!importStyle)
1304
1309
  return void 0;
1305
1310
  if (libName !== "@layui/layui-vue")
1306
1311
  return `${libName}/lib/index.css`;
1307
- let styleDir = _chunkTMX2H7L5js.camelCase.call(void 0, importName.slice(3));
1312
+ let styleDir = lowerCamelCase(importName.slice(3));
1308
1313
  for (const item of matchComponents4) {
1309
1314
  if (item.pattern.test(importName)) {
1310
1315
  styleDir = item.styleDir;
@@ -1325,7 +1330,7 @@ function resolveComponent2(importName, options) {
1325
1330
  } else if (importName.match(layerRE)) {
1326
1331
  name = importName;
1327
1332
  libName = "@layui/layer-vue";
1328
- } else if (importName.match(layuiRE)) {
1333
+ } else if (importName.match(layuiRE) && !importName.match(iconsRE)) {
1329
1334
  name = importName;
1330
1335
  libName = "@layui/layui-vue";
1331
1336
  }
@@ -389,7 +389,7 @@ function ElementPlusResolver(options = {}) {
389
389
  return optionsResolved;
390
390
  optionsResolved = __spreadValues({
391
391
  ssr: false,
392
- version: await getPkgVersion("element-plus", "1.1.0-beta.21"),
392
+ version: await getPkgVersion("element-plus", "2.2.2"),
393
393
  importStyle: "css",
394
394
  directives: true,
395
395
  exclude: void 0
@@ -523,18 +523,20 @@ var specialComponents = {
523
523
  IxAutoComplete: "auto-complete",
524
524
  IxBackTop: "back-top",
525
525
  IxDatePicker: "date-picker",
526
+ IxDateRangePicker: "date-picker",
526
527
  IxCol: "grid",
527
528
  IxRow: "grid",
528
529
  IxInputNumber: "input-number",
529
530
  IxTab: "tabs",
530
531
  IxTreeSelect: "tree-select",
531
- IxTimePicker: "time-picker"
532
+ IxTimePicker: "time-picker",
533
+ IxTimeRangePicker: "time-picker"
532
534
  };
533
535
  function IduxResolver(options = {}) {
534
536
  return {
535
537
  type: "component",
536
538
  resolve: (name) => {
537
- const { importStyle, exclude = [] } = options;
539
+ const { importStyle, importStyleTheme = "default", exclude = [] } = options;
538
540
  if (exclude.includes(name))
539
541
  return;
540
542
  const packageName = getPackageName(name);
@@ -548,7 +550,7 @@ function IduxResolver(options = {}) {
548
550
  const path = `@idux/${packageName}/${dirname}`;
549
551
  let sideEffects;
550
552
  if (packageName !== "cdk" && importStyle)
551
- sideEffects = `${path}/style/themes/${importStyle === "css" ? "default_css" : "default"}`;
553
+ sideEffects = `${path}/style/themes/${importStyle === "css" ? `${importStyleTheme}_css` : importStyleTheme}`;
552
554
  return { name, from: path, sideEffects };
553
555
  }
554
556
  };
@@ -786,7 +788,7 @@ function VarletUIResolver(options = {}) {
786
788
  import { join, normalize } from "path";
787
789
  var VEUI_PACKAGE_NAME = "veui";
788
790
  var components3;
789
- function VeuiResolver(options) {
791
+ function VeuiResolver(options = {}) {
790
792
  const { alias = VEUI_PACKAGE_NAME } = options;
791
793
  if (!components3) {
792
794
  try {
@@ -1298,13 +1300,16 @@ var layuiRE = /^Lay[A-Z]/;
1298
1300
  var layerRE = /^(layer|LayLayer)$/;
1299
1301
  var iconsRE = /^([A-Z][\w]+Icon|LayIcon)$/;
1300
1302
  var libName = "@layui/layui-vue";
1303
+ function lowerCamelCase(str) {
1304
+ return str.charAt(0).toLowerCase() + str.slice(1);
1305
+ }
1301
1306
  function getSideEffects9(importName, options) {
1302
1307
  const { importStyle = "css" } = options;
1303
1308
  if (!importStyle)
1304
1309
  return void 0;
1305
1310
  if (libName !== "@layui/layui-vue")
1306
1311
  return `${libName}/lib/index.css`;
1307
- let styleDir = camelCase(importName.slice(3));
1312
+ let styleDir = lowerCamelCase(importName.slice(3));
1308
1313
  for (const item of matchComponents4) {
1309
1314
  if (item.pattern.test(importName)) {
1310
1315
  styleDir = item.styleDir;
@@ -1325,7 +1330,7 @@ function resolveComponent2(importName, options) {
1325
1330
  } else if (importName.match(layerRE)) {
1326
1331
  name = importName;
1327
1332
  libName = "@layui/layer-vue";
1328
- } else if (importName.match(layuiRE)) {
1333
+ } else if (importName.match(layuiRE) && !importName.match(iconsRE)) {
1329
1334
  name = importName;
1330
1335
  libName = "@layui/layui-vue";
1331
1336
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-vue-components",
3
- "version": "0.19.5",
4
- "packageManager": "pnpm@6.32.3",
3
+ "version": "0.19.6",
4
+ "packageManager": "pnpm@7.1.5",
5
5
  "description": "Components auto importing for Vue",
6
6
  "homepage": "https://github.com/antfu/unplugin-vue-components",
7
7
  "bugs": "https://github.com/antfu/unplugin-vue-components/issues",
@@ -61,6 +61,17 @@
61
61
  ]
62
62
  }
63
63
  },
64
+ "scripts": {
65
+ "build": "tsup && esno scripts/postbuild.ts",
66
+ "dev": "tsup --watch src",
67
+ "example:build": "npm -C examples/vite-vue3 run build",
68
+ "example:dev": "npm -C examples/vite-vue3 run dev",
69
+ "prepublishOnly": "npm run build",
70
+ "lint": "eslint .",
71
+ "release": "bumpp --commit --tag --push",
72
+ "test": "vitest",
73
+ "test:update": "vitest --u"
74
+ },
64
75
  "peerDependencies": {
65
76
  "@babel/parser": "^7.15.8",
66
77
  "@babel/traverse": "^7.15.4",
@@ -111,16 +122,5 @@
111
122
  },
112
123
  "engines": {
113
124
  "node": ">=14"
114
- },
115
- "scripts": {
116
- "build": "tsup && esno scripts/postbuild.ts",
117
- "dev": "tsup --watch src",
118
- "example:build": "npm -C examples/vite-vue3 run build",
119
- "example:dev": "npm -C examples/vite-vue3 run dev",
120
- "lint": "eslint .",
121
- "release": "bumpp --commit --tag --push",
122
- "test": "vitest",
123
- "test:update": "vitest --u"
124
- },
125
- "readme": "# unplugin-vue-components\n\n[![NPM version](https://img.shields.io/npm/v/unplugin-vue-components?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-vue-components)\n\nOn-demand components auto importing for Vue.\n\n###### Features\n\n- 💚 Supports both Vue 2 and Vue 3 out-of-the-box.\n- ✨ Supports both components and directives.\n- ⚡️ Supports Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by <a href=\"https://github.com/unjs/unplugin\">unplugin</a>.\n- 🏝 Tree-shakable, only registers the components you use.\n- 🪐 Folder names as namespaces.\n- 🦾 Full TypeScript support.\n- 🌈 [Built-in resolvers](#importing-from-ui-libraries) for popular UI libraries.\n- 😃 Works perfectly with [unplugin-icons](https://github.com/antfu/unplugin-icons).\n\n<br>\n\n<p align=\"center\">\n <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n </a>\n</p>\n\n<br>\n\n## Installation\n\n```bash\nnpm i unplugin-vue-components -D\n```\n\n> **`vite-plugin-components` has been renamed to `unplugin-vue-components`**, see the [migration guide](#migrate-from-vite-plugin-components).\n\n<details>\n<summary>Vite</summary><br>\n\n```ts\n// vite.config.ts\nimport Components from 'unplugin-vue-components/vite'\n\nexport default defineConfig({\n plugins: [\n Components({ /* options */ }),\n ],\n})\n```\n\n<br></details>\n\n<details>\n<summary>Rollup</summary><br>\n\n```ts\n// rollup.config.js\nimport Components from 'unplugin-vue-components/rollup'\n\nexport default {\n plugins: [\n Components({ /* options */ }),\n ],\n}\n```\n\n<br></details>\n\n\n<details>\n<summary>Webpack</summary><br>\n\n```ts\n// webpack.config.js\nmodule.exports = {\n /* ... */\n plugins: [\n require('unplugin-vue-components/webpack')({ /* options */ }),\n ],\n}\n```\n\n<br></details>\n\n<details>\n<summary>Nuxt</summary><br>\n\nYou might not need this plugin for Nuxt. Use [`@nuxt/components`](https://github.com/nuxt/components) instead.\n\n<br></details>\n\n<details>\n<summary>Vue CLI</summary><br>\n\n```ts\n// vue.config.js\nmodule.exports = {\n configureWebpack: {\n plugins: [\n require('unplugin-vue-components/webpack')({ /* options */ }),\n ],\n },\n}\n```\n\n<br></details>\n\n<details>\n<summary>esbuild</summary><br>\n\n```ts\n// esbuild.config.js\nimport { build } from 'esbuild'\n\nbuild({\n /* ... */\n plugins: [\n require('unplugin-vue-components/esbuild')({\n /* options */\n }),\n ],\n})\n```\n\n<br></details>\n\n## Usage\n\nUse 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.\n\nIt will automatically turn this\n\n```html\n<template>\n <div>\n <HelloWorld msg=\"Hello Vue 3.0 + Vite\" />\n </div>\n</template>\n\n<script>\nexport default {\n name: 'App'\n}\n</script>\n```\n\ninto this\n\n```html\n<template>\n <div>\n <HelloWorld msg=\"Hello Vue 3.0 + Vite\" />\n </div>\n</template>\n\n<script>\nimport HelloWorld from './src/components/HelloWorld.vue'\n\nexport default {\n name: 'App',\n components: {\n HelloWorld\n }\n}\n</script>\n```\n\n## TypeScript\n\nTo get TypeScript support for auto-imported components, there is [a PR](https://github.com/vuejs/vue-next/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.\n\n```ts\nComponents({\n dts: true, // enabled by default if `typescript` is installed\n})\n```\n\nOnce 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.\n\n**Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**\n\n## Importing from UI Libraries\n\nWe have several built-in resolvers for popular UI libraries like **Vuetify**, **Ant Design Vue**, and **Element Plus**, where you can enable them by:\n\nSupported Resolvers:\n\n- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)\n- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)\n- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)\n- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)\n- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)\n- [IDux](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/idux.ts)\n- [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)\n- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)\n- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)\n- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)\n- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)\n- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)\n- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)\n- [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts)\n- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)\n- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)\n- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)\n\n```ts\n// vite.config.js\nimport Components from 'unplugin-vue-components/vite'\nimport {\n AntDesignVueResolver,\n ElementPlusResolver,\n VantResolver,\n} from 'unplugin-vue-components/resolvers'\n\n// your plugin installation\nComponents({\n resolvers: [\n AntDesignVueResolver(),\n ElementPlusResolver(),\n VantResolver(),\n ],\n})\n```\n\nYou can also write your own resolver quickly:\n\n```ts\nComponents({\n resolvers: [\n // example of importing Vant\n (componentName) => {\n // where `componentName` is always CapitalCase\n if (componentName.startsWith('Van'))\n return { name: componentName.slice(3), from: 'vant' }\n },\n ],\n})\n```\n\nIf you successfully configured other UI libraries, please feel free to contribute and help others using them out-of-box. Thanks!\n\n## Types for global registered components\n\nSome 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.\n\nThus `unplugin-vue-components` provided a way to only register types for global components.\n\n```ts\nComponents({\n dts: true,\n types: [{\n from: 'vue-router',\n names: ['RouterLink', 'RouterView'],\n }],\n})\n```\n\nSo the `RouterLink` and `RouterView` will be presented in `components.d.ts`.\n\nBy default, `unplugin-vue-components` detects supported libraries automatically (e.g. `vue-router`) when their are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:\n\n```ts\nComponents({\n // Disable type only registration\n types: [],\n})\n```\n\n## Migrate from `vite-plugin-components`\n\n`package.json`\n\n```diff\n{\n \"devDependencies\": {\n- \"vite-plugin-components\": \"*\",\n+ \"unplugin-vue-components\": \"^0.14.0\",\n }\n}\n```\n\n`vite.config.json`\n\n```diff\n- import Components, { ElementPlusResolver } from 'vite-plugin-components'\n+ import Components from 'unplugin-vue-components/vite'\n+ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'\n\nexport default {\n plugins: [\n /* ... */\n Components({\n /* ... */\n\n // `customComponentsResolvers` has renamed to `resolver`\n- customComponentsResolvers: [\n+ resolvers: [\n ElementPlusResolver(),\n ],\n\n // `globalComponentsDeclaration` has renamed to `dts`\n- globalComponentsDeclaration: true,\n+ dts: true,\n\n // `customLoaderMatcher` is depreacted, use `include` instead\n- customLoaderMatcher: id => id.endsWith('.md'),\n+ include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n }),\n ],\n}\n```\n\n## Configuration\n\nThe following show the default values of the configuration\n\n```ts\nComponents({\n // relative paths to the directory to search for components.\n dirs: ['src/components'],\n\n // valid file extensions for components.\n extensions: ['vue'],\n // search for subdirectories\n deep: true,\n // resolvers for custom components\n resolvers: [],\n\n // generate `components.d.ts` global declarations,\n // also accepts a path for custom filename\n // default: `true` if package typescript is installed\n dts: false,\n\n // Allow subdirectories as namespace prefix for components.\n directoryAsNamespace: false,\n // Subdirectory paths for ignoring namespace prefixes\n // works when `directoryAsNamespace: true`\n globalNamespaces: [],\n\n // auto import for directives\n // default: `true` for Vue 3, `false` for Vue 2\n // Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.\n // To install Babel, run: `npm install -D @babel/parser @babel/traverse`\n directives: true,\n\n // filters for transforming targets\n include: [/\\.vue$/, /\\.vue\\?vue/],\n exclude: [/[\\\\/]node_modules[\\\\/]/, /[\\\\/]\\.git[\\\\/]/, /[\\\\/]\\.nuxt[\\\\/]/],\n})\n```\n\n## Example\n\nSee the [Vitesse](https://github.com/antfu/vitesse) starter template.\n\n## Thanks\n\nThanks to [@brattonross](https://github.com/brattonross), this project is heavily inspired by [vite-plugin-voie](https://github.com/vamplate/vite-plugin-voie).\n\n## License\n\nMIT License © 2020-PRESENT [Anthony Fu](https://github.com/antfu)\n"
126
- }
125
+ }
126
+ }