unplugin-element-plus

Import Element Plus on demand. Support Vite, Webpack, Vue CLI, Rollup and esbuild.
1,523,768 252
Install
npm install unplugin-element-plus
Latest Version:0.11.2
Vue:3
Older releases:2
License:MIT
Last Updated:Oct 16, 2026
Links: GitHub  ·  npm
Maintainer: jeremywuuuuu

unplugin-element-plus

Unit Test

English | 中文

这个仓库是用于 Element Plus 相关的 unplugin 插件工具。感谢 @antfu。

功能
  • 💚 为 Element Plus 按需引入样式。
  • 🌎 替换默认语言。
  • ⚡️ 使用 unplugin 以支持 Vite, Webpack, Vue CLI, Rollup, esbuild 等。

安装

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

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

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

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

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

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

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

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

使用

插件会自动转换:

import { ElButton } from 'element-plus'

//    ↓ ↓ ↓ ↓ ↓ ↓

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

选项

useSource

type UseSource = boolean
// 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

一般这个是用不到的,不过作为一个通用选项,还是暴露了出来,如果有用到这个的结构一定要和 ElementPlus 的输出包结构一致,详见 unpkg.com

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 对应 [lib]/es/components/*

cjs 对应 [lib]/lib/components/*

  • /es 对应 ES Module 输出
  • /lib 对应 CommonJS 的输出

使用该选项来选择使用哪一个包。

// 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[]

跳过组件列表的样式导入。 对于没有样式文件的 Element Plus 组件很有用。 在编写此文档时,仅有“AutoResizer”组件。

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

//    ↓ ↓ ↓ ↓ ↓ ↓

import { ElAutoResizer } from 'element-plus'

defaultLocale

替换默认语言,你可以 在这 查看所有语言列表。

其他插件

Related Packages

unplugin-vue-named-export

Named export for Vue SFC.

9,463 22
vite-plugin-resize-image

📦 📦 unplugin compression Image Compression plugin based on squoosh and sharp

682
unplugin-vue

Transform Vue 3 SFC to JavaScript.

1,075,622 274
vite-minify-css-module

📦 📦 unplugin minify css module

2,293

Version History

Version Released License
0.11.2 MIT
0.11.1 MIT
0.11.0 MIT
0.10.0 MIT
0.9.1 MIT