# unplugin-element-plus **Repository Path**: osAce/unplugin-element-plus ## Basic Information - **Project Name**: unplugin-element-plus - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-30 - **Last Updated**: 2021-09-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README


# unplugin-element-plus [English](README.md) | [中文](README.zh-CN.md) 这个仓库是用于 `Element Plus` 相关的 [unplugin](https://github.com/unjs/unplugin) 插件工具。感谢 [@antfu](https://github.com/antfu)。 ###### 功能 - 💚 为 Element Plus 按需引入样式。 - ⚡️ 使用 unplugin 以支持 Vite, Webpack, Vue CLI, Rollup 等。 ## 安装 ```bash npm i unplugin-element-plus -D ```
Vite
```ts // vite.config.ts import ElementPlus from 'unplugin-element-plus/vite' export default { plugins: [ ElementPlus({ // options }), ], } ```
Rollup
```ts // rollup.config.js import ElementPlus from 'unplugin-element-plus/rollup' export default { plugins: [ ElementPlus({ // options }), ], } ```
Webpack
```ts // webpack.config.js module.exports = { /* ... */ plugins: [ require('unplugin-element-plus/webpack')({ // options }), ], } ```
Vue CLI
```ts // vue.config.js module.exports = { configureWebpack: { plugins: [ require('unplugin-element-plus/webpack')({ // options }), ], }, } ```
## 使用 插件会自动转换: ```javascript import { ElButton } from 'element-plus' ↓ ↓ ↓ ↓ ↓ ↓ import { ElButton } from 'element-plus' import 'element-plus/es/components/button/style/css' ``` ## 选项 ### `useSource` ```ts type UseSource = boolean ``` ```javascript // 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](https://unpkg.com/element-plus) ```ts type Lib = string ``` default: 'element-plus' ```javascript // lib: 'other-lib' import { ElButton } from 'other-lib' ↓ ↓ ↓ ↓ ↓ ↓ import { ElButton } from 'other-lib' import 'other-lib/es/components/button/style/css' ``` ### format ```ts type Format = 'esm' | 'cjs' ``` default: 'esm' **esm** 对应 `[lib]/es/components/*` **cjs** 对应 `[lib]/lib/components/*` - /es 对应 ES Module 输出 - /lib 对应 commonJS 的输出 使用该选项来选择使用哪一个包。 ```javascript // format: 'cjs' import { ElButton } from 'element-plus' ↓ ↓ ↓ ↓ ↓ ↓ import { ElButton } from 'element-plus' import 'element-plus/lib/components/button/style/css' ``` ### prefix ```ts type Prefix = string ``` ```javascript // prefix = Al import { AlButton } from 'xx-lib' ``` ## 其他插件 - [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)