unplugin-element-plus
v0.11.1
Published
<p align="center"> <img width="300px" src="https://user-images.githubusercontent.com/10731096/95823103-9ce15780-0d5f-11eb-8010-1bd1b5910d4f.png"> </p>
Maintainers
Readme
unplugin-element-plus
这个仓库是用于 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 = stringdefault: '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
替换默认语言,你可以 在这 查看所有语言列表。
