-
-
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/ui
- Loading branch information
Showing
4 changed files
with
76 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,82 @@ | ||
# 快速开始 | ||
# Import On Demand | ||
|
||
## 介绍 | ||
### 介绍 | ||
The on-demand import avoids the full import of components and can effectively reduce the size of the distribution package. | ||
It is recommended to use `Plugin Based Introduction` or `ES module based manual introduction` | ||
|
||
这里为您介绍常见开发模式下接入组件库的最基本方式。 | ||
### Plugin based introduction | ||
|
||
## 安装 | ||
|
||
### CDN | ||
`varlet.js`包含组件库的所有样式和逻辑, 引入即可。 | ||
### Webpack | ||
```shell | ||
# Install plugin | ||
# npm | ||
npm i babel-plugin-import -D | ||
# yarn | ||
yarn add babel-plugin-import -D | ||
``` | ||
|
||
```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> | ||
```js | ||
// babel.config.js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
'import', | ||
{ | ||
libraryName: '@varlet/ui', | ||
libraryDirectory: 'es', | ||
style: true, | ||
}, | ||
'@varlet/ui', | ||
], | ||
], | ||
}; | ||
``` | ||
|
||
### Webpack/Vite | ||
### Vite | ||
|
||
```shell | ||
# 通过npm或yarn安装 | ||
# Install plugin | ||
# npm | ||
npm i @varlet/ui -S | ||
npm i vite-plugin-style-import -D | ||
# yarn | ||
yarn add @varlet/ui | ||
yarn add vite-plugin-style-import -D | ||
``` | ||
|
||
```js | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
import Varlet from '@varlet/ui' | ||
import '@varlet/ui/es/style' | ||
// 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`, | ||
}, | ||
] | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
After the configuration is complete, and the component is imported as follows, | ||
the plugin will automatically import the corresponding style file for the component | ||
|
||
```html | ||
import { Button } from '@varlet/ui' | ||
``` | ||
|
||
createApp(App).use(Varlet).mount('#app') | ||
``` | ||
### ES module based manual introduction | ||
|
||
The ES module is very tree-shaking friendly, | ||
and you can manually import the required component logic and style files directly to implement on-demand introduction. | ||
|
||
```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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# 快速开始 | ||
|
||
## 介绍 | ||
### 介绍 | ||
|
||
这里为您介绍常见开发模式下接入组件库的最基本方式。 | ||
|
||
## 安装 | ||
### 安装 | ||
|
||
### CDN | ||
`varlet.js`包含组件库的所有样式和逻辑, 引入即可。 | ||
|