Skip to content

Commit

Permalink
fix: test prefetch and add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghuimin45 committed Nov 8, 2023
1 parent 2656f75 commit 3299ff5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions dev/main-react16/src/pages/vue2/vue2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import config from '../../config'
import './vue2.less'
import lessStyles from './module.less'

microApp.start({
preFetchApps: [
{ name: 'my-app1', url: 'https://storage.360buyimg.com/launch/zeromock/umd-module.js', level: 3 }, // 加载资源并解析
],
})


const antIcon = <LoadingOutlined style={{ fontSize: 30 }} spin />

function Vue2 () {
Expand All @@ -18,6 +25,10 @@ function Vue2 () {
function mounted () {
console.timeEnd('mounted-vue2')
console.log('生命周期:mounted -- vue2', document.querySelector('micro-app'))
microApp.preFetch([
{ name: 'my-app1', url: 'https://storage.360buyimg.com/launch/zeromock/umd-module.js', level: 3 }, // 加载资源并解析
])

hideLoading(false)
}

Expand Down
17 changes: 17 additions & 0 deletions docs/zh-cn/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,20 @@ microApp.start({

> [!NOTE]
> 1、如果跨域请求带cookie,那么`Access-Control-Allow-Origin`不能设置为`*`,必须指定域名,同时设置`Access-Control-Allow-Credentials: true`
## 2、微组件

一个正常的 micro-app 子应用可以这样注册:

```js
<micro-app name='my-app' url='http://localhost:3000/'></micro-app>
```

为了实现加载js文件实现微组件的能力,我们url属性将以前仅支持html地址,升级成既支持html地址,也支持js等模块化文件。用法如下:

```js
<micro-app name='xx' url='http://xxx.js'></micro-app>
```

> [!NOTE]
> 1、微组件只是极个别场景下的解决方案(目前识别到的只有扩展点和细粒度重构),其他场景并不建议使用微组件。
2 changes: 2 additions & 0 deletions src/__tests__/unit/mocks/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const MOCK_APP_URL = 'http://localhost:6666/'

export const MOCK_APP_URL_UMD = 'https://storage.360buyimg.com/launch/zeromock/umd-module.js'

export const MOCK_APP_URL_UMD_OTHER = 'https://storage.360buyimg.com/launch/zeromock/umd-module-cpoy.js'
3 changes: 1 addition & 2 deletions src/source/loader/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export class HTMLLoader implements IHTMLLoader {
public run (app: AppInterface, successCb: CallableFunction): void {
const appName = app.name
const htmlUrl = app.ssrUrl || app.url
const regex = /\.js$/
const htmlPromise = regex.test(htmlUrl)
const htmlPromise = htmlUrl.includes('.js')
? Promise.resolve(`<micro-app-head><script src='${htmlUrl}'></script></micro-app-head><micro-app-body></micro-app-body>`)
: fetchSource(htmlUrl, appName, { cache: 'no-cache' })
htmlPromise.then((htmlStr: string) => {
Expand Down

0 comments on commit 3299ff5

Please sign in to comment.