import-html
the middleware to load resources from html
Installation
npm install obvious-import-html
or
yarn add obvious-import-html
Usage
You can specify the html entry when you use the middleware
import { touchBus } from 'obvious-core'
import importHtml from 'obvious-import-html'
const [bus, isHost] = touchBus()
if (isHost) {
bus.use(importHtml({
'host-app': 'https://cdn.yours.com/host-app/index.html',
'react-app': 'https://cdn.yours.com/react-app/index.html',
'vue-app': 'https://cdn.yours.com/vue-app/index.html'
}))
}
bus.activateApp('host-app')
Or you can use the loadHtml in the next middleware
import { touchBus } from 'obvious-core'
import importHtml from 'obvious-import-html'
const [bus, isHost] = touchBus()
if (isHost) {
bus.use(importHtml()).use(async (ctx, next) => {
const success = await ctx.loadHtml(`https://cdn.yours.com/${ctx.name}/index.html`)
if (!success) {
await next()
}
})
}
bus.activateApp('host-app')
License
obvious-import-html is MIT Licensed