• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔌 Import Element Plus on demand. Support Vite, Webpack, Vue CLI, Rollup and esbuild.


unplugin-element-plus

Unit Test

English | 中文

This repo is for element-plus related unplugin. Thanks @antfu.

Features
  • 💚 On-demand import style for Element Plus.
  • 🌎 Replace default locale.
  • ⚡️ Supports Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by unplugin.

Installation

npm i unplugin-element-plus -D
Vite
// vite.config.ts
import ElementPlus from 'unplugin-element-plus/vite'

export default {
  plugins: [
    ElementPlus({
      // options
    }),
  ],
}


Rollup
// rollup.config.js
import ElementPlus from 'unplugin-element-plus/rollup'

export default {
  plugins: [
    ElementPlus({
      // options
    }),
  ],
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [
    require('unplugin-element-plus/esbuild')({
      // options
    }),
  ],
})


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-element-plus/webpack')({
      // options
    }),
  ],
}


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-element-plus/webpack')({
        // options
      }),
    ],
  },
}


Usage

It will automatically transform:

import { ElButton } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElButton } from 'element-plus'
import 'element-plus/es/components/button/style/css'

Options

useSource

type UseSource = boolean

default: false

// useSource: false
import { ElButton } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElButton } from 'element-plus'
import 'element-plus/es/components/button/style/css'

// useSource: true
import { ElButton } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElButton } from 'element-plus'
import 'element-plus/es/components/button/style/index'

lib

Normally you wouldn't use this option but as a general option we exposed it anyway. When using this your bundle structure should be the same as ElementPlus. See unpkg.com for more information.

type Lib = string

default: 'element-plus'

// lib: 'other-lib'
import { ElButton } from 'other-lib'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElButton } from 'other-lib'
import 'other-lib/es/components/button/style/css'

format

type Format = 'esm' | 'cjs'

default: 'esm'

esm for element-plus/es/components/*

cjs for element-plus/lib/components/*

  • /es for ES Module
  • /lib for CommonJS

This option is for which format to use

// format: 'cjs'
import { ElButton } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElButton } from 'element-plus'
import 'element-plus/lib/components/button/style/css'

prefix

type Prefix = string
// prefix = Al
import { AlButton } from 'xx-lib'

ignoreComponents

type IgnoreComponents = string[]

Skip style imports for a list of components. Useful for Element Plus components which do not have a style file. At the time of writing, this is only the AutoResizer component.

// format: 'cjs'
import { ElAutoResizer } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElAutoResizer } from 'element-plus'

defaultLocale

Replace default locale, you can find locale list here.

Alternate

More Repositories

1

element-plus

🎉 A Vue.js 3 UI Library made by Element team
TypeScript
24,417
star
2

element-plus-vite-starter

🌰 A starter kit for Element Plus with Vite
Vue
1,123
star
3

element-plus-nuxt-starter

🌰 A starter example for element-plus with Nuxt 3.
Vue
295
star
4

element-plus-playground

Element Plus Playground
TypeScript
174
star
5

element-plus-icons

Main package for storing Element Plus icon resources.
TypeScript
142
star
6

element-plus-nuxt

Element Plus module for Nuxt
Vue
128
star
7

element-plus-vue-cli-starter

A starter kit for Element Plus generated by vue-cli
Vue
127
star
8

vue-cli-plugin-element-plus

Element Plus plugin for @vue/cli 4.5
JavaScript
122
star
9

element-plus-interactive-docs

🎉 [WIP] Element Plus Interactive Docs
Vue
62
star
10

element-plus-in-laravel-starter

Laravel Project with Vue3 and Element Plus
JavaScript
24
star
11

vite-plugin-element-plus

This repo is for element-plus related Vite plugin
TypeScript
15
star
12

theme-chalk-preview

Preview and download custom Element Plus theme-chalk.
TypeScript
7
star
13

element-plus-issue-helper

Issue helper for Element Plus
Vue
6
star
14

colors

🎨 This repository is meant for build color utils for theme customization
TypeScript
6
star
15

design-materials

5
star
16

headless

Headless code for components
3
star
17

doc-archive

Old document website backup
JavaScript
3
star
18

el-context-menu

The main repository for el-context-menu built upon ElementPlus
2
star
19

element-plus-webpack5-starter

🌰 A starter kit for Element Plus with Webpack 5.
TypeScript
1
star
20

staging

development website of element-plus
HTML
1
star