-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
affects: @varlet/cli, @varlet/ui
- Loading branch information
Showing
8 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 快速开始 | ||
|
||
## 介绍 | ||
|
||
这里为您介绍常见开发模式下接入组件库的最基本方式。 | ||
|
||
## 安装 | ||
|
||
### CDN | ||
`varlet.js`包含组件库的所有样式和逻辑, 引入即可。 | ||
|
||
```html | ||
<div id="app"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@varlet/ui/umd/varlet.js"></script> | ||
<script> | ||
const app = Vue.createApp({ | ||
template: '<var-button>按钮</var-button>' | ||
}) | ||
app.use(Varlet).mount('#app') | ||
</script> | ||
``` | ||
|
||
### Webpack/Vite | ||
```shell | ||
# 通过npm或yarn安装 | ||
# npm | ||
npm i @varlet/ui -S | ||
# yarn | ||
yarn add @varlet/ui | ||
``` | ||
|
||
```js | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
import Varlet from '@varlet/ui' | ||
import '@varlet/ui/es/style' | ||
|
||
createApp(App).use(Varlet).mount('#app') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# 按需引入 | ||
|
||
## 介绍 | ||
按需引入避免了组件的全量导入,可以有效的减少发布包的大小。 | ||
这里推荐`基于插件的引入方式`或`基于es模块的手动引入方式` | ||
|
||
## 基于插件的引入方式 | ||
|
||
### Webpack | ||
```shell | ||
# 安装插件 | ||
# npm | ||
npm i babel-plugin-import -D | ||
# yarn | ||
yarn add babel-plugin-import -D | ||
``` | ||
|
||
```js | ||
// babel.config.js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
'import', | ||
{ | ||
libraryName: '@varlet/ui', | ||
libraryDirectory: 'es', | ||
style: true, | ||
}, | ||
'@varlet/ui', | ||
], | ||
], | ||
}; | ||
``` | ||
|
||
### Vite | ||
|
||
```shell | ||
# 安装插件 | ||
# npm | ||
npm i vite-plugin-style-import -D | ||
# yarn | ||
yarn add vite-plugin-style-import -D | ||
``` | ||
|
||
```js | ||
// vite.config.js | ||
import vue from '@vitejs/plugin-vue' | ||
import styleImport from 'vite-plugin-style-import' | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
vue(), | ||
styleImport({ | ||
libs: [ | ||
{ | ||
libraryName: '@varlet/ui', | ||
esModule: true, | ||
resolveStyle: name => `@varlet/ui/es/${name}/style/index`, | ||
}, | ||
] | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
完成配置之后,如下引入组件,插件会自动引入组件对应的样式文件。 | ||
|
||
```html | ||
import { Button } from '@varlet/ui' | ||
``` | ||
|
||
## 基于es模块的手动引入方式 | ||
|
||
es模块对于tree-shaking十分友好,您也可以直接手动引入需要的组件逻辑和样式文件来实现按需引入。 | ||
|
||
```html | ||
import { Button } from '@varlet/ui' | ||
import '@varlet/ui/es/button/style' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
# Quickstart | ||
# Quickstart | ||
|
||
## Intro | ||
|
||
Here are the most basic ways to access component libraries in common development patterns. | ||
|
||
## Install | ||
|
||
### CDN | ||
`varlet.js` contain all the styles and logic of the component library, and you can import them. | ||
|
||
```html | ||
<div id="app"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@varlet/ui/umd/varlet.js"></script> | ||
<script> | ||
const app = Vue.createApp({ | ||
template: '<var-button>按钮</var-button>' | ||
}) | ||
app.use(Varlet).mount('#app') | ||
</script> | ||
``` | ||
|
||
### Webpack/Vite | ||
```shell | ||
# Install with npm or yarn | ||
# npm | ||
npm i @varlet/ui -S | ||
# yarn | ||
yarn add @varlet/ui | ||
``` | ||
|
||
```js | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
import Varlet from '@varlet/ui' | ||
import '@varlet/ui/es/style' | ||
|
||
createApp(App).use(Varlet).mount('#app') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ export interface Dialog { | |
close(): void | ||
Component: DialogComponent | ||
} | ||
|
||
export const Dialog: Dialog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ export interface Picker { | |
close(): void | ||
Component: PickerComponent | ||
} | ||
|
||
export const Picker: Picker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters