Skip to content

Commit

Permalink
release: v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-winter committed Jul 16, 2022
1 parent 9541b05 commit 42da95a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
### 简介
# vite-plugin-qiankun

> 简化 `vite` 子应用接入 `qiankun` 的流程

### 快速开始
简化 `vite` 子应用接入 `qiankun` 的流程

## 要求

此包适用于 vite 2.6+ ,不包含 vite 3.0。

## 安装

使用 `npm`:

```console
$ npm install @sh-winter/vite-plugin-qiankun --save-dev
```



## 用法

### 1. 注册插件

#### 1. 安装 `vite` 插件
```ts
// vite.config.ts

import qiankun from '@sh-winter/vite-plugin-qiankun'
import { name as packageName } from './package.json'

Expand All @@ -19,10 +34,10 @@ export default {
}
```

#### 2. 导出 `qiankun` 生命周期钩子
### 2. 子应用导出 `qiankun` 生命周期钩子

```ts
// main.ts

import { exportLifeCycleHooks, qiankunWindow } from '@sh-winter/vite-plugin-qiankun/dist/helper'

// some code
Expand All @@ -49,14 +64,16 @@ if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
}
```

#### 3. 注意事项
### 3. 注意事项

1. `es module` 会导致 `qiankun` 沙箱失效,如果想要访问 `qiankun` 提供的代理 `window`,请使用 `qiankunWindow`

```ts
import { qiankunWindow } from '@sh-winter/vite-plugin-qiankun/dist/helper'
import { qiankunWindow } from '@sh-winter/vite-plugin-qiankun/dist/helper'
```

2. 如果是 `vue` 子应用,开发环境下需要额外引入 `vue-template-compiler transform` 插件:`transformAssetUrl`

```ts
// vite.config.ts

Expand All @@ -77,8 +94,8 @@ if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
}
```

### 查看示例
## 查看示例

```bash
yarn example
```
npm run example
```
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sh-winter/vite-plugin-qiankun",
"version": "0.1.1",
"version": "2.0.0",
"description": "vite qiankun plugin",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -30,7 +30,7 @@
"cheerio": "^1.0.0-rc.10",
"srcset": "4.0.0",
"valid-data-url": "^4.0.0",
"vite": ">=2"
"vite": "^2.9.9"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.3.0",
Expand All @@ -50,7 +50,7 @@
"typescript": "^4.5.5"
},
"peerDependencies": {
"@vue/compiler-sfc": ">=3",
"vite": ">=2"
"@vue/compiler-sfc": ">=3.2.0",
"vite": ">=2.6.0"
}
}

0 comments on commit 42da95a

Please sign in to comment.