All Projects → antfu → Vite Plugin Components

antfu / Vite Plugin Components

Licence: mit
📲 On-demand components auto importing for Vite

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vite Plugin Components

Igniteui Angular Wrappers
Ignite UI Angular component extensions by Infragistics
Stars: ✭ 150 (-14.29%)
Mutual labels:  components
Qui
A Vue.js design-system for Web.
Stars: ✭ 165 (-5.71%)
Mutual labels:  components
Terraform Aws Components
Opinionated, self-contained Terraform root modules that each solve one, specific problem
Stars: ✭ 168 (-4%)
Mutual labels:  components
Shine Design
为开发者、设计师和产品经理准备的 UI 设计语言
Stars: ✭ 157 (-10.29%)
Mutual labels:  components
Ngx Currency
📦 Currency mask module for Angular
Stars: ✭ 161 (-8%)
Mutual labels:  components
Terra Core
Terra offers a set of configurable React components designed to help build scalable and modular application UIs. This UI library was created to solve real-world issues in projects we work on day to day.
Stars: ✭ 167 (-4.57%)
Mutual labels:  components
Hanzi chaizi
汉字拆字库,可以将汉字拆解成偏旁部首,在机器学习中作为汉字的字形特征
Stars: ✭ 146 (-16.57%)
Mutual labels:  components
Lucid
A UI component library from AppNexus.
Stars: ✭ 171 (-2.29%)
Mutual labels:  components
Amexio.github.io
Amexio is a rich set of Angular 7 (170+) components powered by HTML5 & CSS3 for Responsive Design and with 80+ Material Design Themes, UI Components, Charts, Gauges, Data Point Widgets, Dashboards. Amexio is completely Open Sourced and Free. It's based on Apache 2 License. You can use it in your production grade work today at no cost or no obligation.
Stars: ✭ 163 (-6.86%)
Mutual labels:  components
Fela
State-Driven Styling in JavaScript
Stars: ✭ 2,097 (+1098.29%)
Mutual labels:  components
Iso
Build pages and prototypes with Lab UI components. No configuration or build setup required.
Stars: ✭ 158 (-9.71%)
Mutual labels:  components
Flama
🔥 Fire up your API with this flamethrower
Stars: ✭ 161 (-8%)
Mutual labels:  components
Vue Design System
An open source tool for building UI Design Systems with Vue.js
Stars: ✭ 2,077 (+1086.86%)
Mutual labels:  components
Gwt Polymer Elements
Polymer Web Components for GWT. A collection of Material Design widgets for desktop and mobile.
Stars: ✭ 153 (-12.57%)
Mutual labels:  components
Semantic Ui React
The official Semantic-UI-React integration
Stars: ✭ 12,561 (+7077.71%)
Mutual labels:  components
React Storybook Addon Chapters
📒 Showcase multiple React components within a story
Stars: ✭ 149 (-14.86%)
Mutual labels:  components
React Messenger
Chat UX components built with React, inspired by Facebook Messenger
Stars: ✭ 167 (-4.57%)
Mutual labels:  components
Zent
A collection of essential UI components written with React.
Stars: ✭ 2,133 (+1118.86%)
Mutual labels:  components
Vui
💯 A personal Vue UI component library for Mobile
Stars: ✭ 171 (-2.29%)
Mutual labels:  components
Ng Aquila
Angular UI Component library for the Open Insurance Platform
Stars: ✭ 170 (-2.86%)
Mutual labels:  components

vite-plugin-components

On demand components auto importing for Vite



Usage

ℹ️ Vite 2 is supported from v0.6.x, Vite 1's support is discontinued.

Install

npm i vite-plugin-components -D # yarn add vite-plugin-components -D

Add it to vite.config.js

// vite.config.js
import Vue from '@vitejs/plugin-vue'
import ViteComponents from 'vite-plugin-components'

export default {
  plugins: [
    Vue(),
    ViteComponents()
  ],
};

That's all.

Use components in templates as you would usually do but NO import and component registration required anymore! It will import components on demand, code splitting is also possible.

Basically, it will automatically turn this

<template>
  <div>
    <HelloWorld msg="Hello Vue 3.0 + Vite" />
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

into this

<template>
  <div>
    <HelloWorld msg="Hello Vue 3.0 + Vite" />
  </div>
</template>

<script>
import HelloWorld from './src/components/HelloWorld.vue'

export default {
  name: 'App',
  components: {
    HelloWorld
  }
}
</script>

Vue 2 Support

It just works.

// vite.config.js
import { createVuePlugin } from 'vite-plugin-vue2'
import ViteComponents from 'vite-plugin-components'

export default {
  plugins: [
    createVuePlugin(),
    ViteComponents(),
  ],
}

Importing from UI Libraries

We have several built-in resolver for popular UI libraries like Ant Design Vue and Element Plus, where you can enable them by:

// vite.config.js
import ViteComponents, {
  AntDesignVueResolver,
  ElementPlusResolver,
  VantResolver,
} from 'vite-plugin-components'

export default {
  plugins: [
    /* ... */
    ViteComponents({
      customComponentResolvers: [
        AntDesignVueResolver(),
        ElementPlusResolver(),
        VantResolver(),
      ]
    }),
  ],
}

Or you can write your own resolver quite easily:

// vite.config.js
import ViteComponents from 'vite-plugin-components'

export default {
  plugins: [
    /* ... */
    ViteComponents({
      customComponentResolvers: [
        // example of importing Vant
        (name) => {
          // where `name` is always CapitalCase
          if (name.startsWith('Van'))
            return { importName: name.slice(3), path: 'vant' }
        }
      ]
    }),
  ],
}

If made other UI libraries configured, please feel free to contribute so it can help others using them out-of-box. Thanks!

Configuration

The following show the default values of the configuration

ViteComponents({
  // relative paths to the directory to search for components.
  dirs: ['src/components'],

  // valid file extensions for components.
  extensions: ['vue'],
  // search for subdirectories
  deep: true,

  // Allow subdirectories as namespace prefix for components.
  directoryAsNamespace: false,
  // Subdirectory paths for ignoring namespace prefixes
  // works when `directoryAsNamespace: true`
  globalNamespaces: [],
})

Example

See the Vitesse starter template.

Thanks

Thanks to @brattonross, this project is heavily inspired by vite-plugin-voie.

License

MIT License © 2020 Anthony Fu

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].