umijs / qiankun

📦 🚀 Blazing fast, simple and complete solution for micro frontends.
https://qiankun.umijs.org
MIT License
15.85k stars 2.02k forks source link

How can I configure a vite-svelte subapp? #2198

Open Relaxe111 opened 2 years ago

Relaxe111 commented 2 years ago

Hi, i try for some time to figure out how to make a vite svelte subapp to work with qiankun, and i can't figure out. Maybe have someone an example project how can i do that?

Many thanks in advance!

gongshun commented 2 years ago

https://github.com/umijs/qiankun/issues/1777#issuecomment-1035873054

https://github.com/tengmaoqing/vite-plugin-qiankun

Relaxe111 commented 2 years ago

@gongshun thankyou for answer. I use this plugin with react, problem with svelte is that it has no .render() function its main.ts is

// main.ts for svelte vite project
import App from './App.svelte'

const app = new App({
  target: document.getElementById('app')
})

export default app

i can't figure out how to do something like i do With react app:

// main.tsx for vite react project
let root: Root;
console.log(React);

function render(props: any) {
  const { container } = props;
  root = ReactDOM.createRoot(container
    ? container.querySelector("#root")
    : document.getElementById("root"))

  root.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>
  )
}

renderWithQiankun({
  mount(props) {
    console.log("react18 mount");
    render(props);
  },
  bootstrap() {
    console.log("bootstrap");
  },
  unmount(props: any) {
    console.log("react18 unmount");
    root.unmount();
  },
  update(props: any) {
    console.log("react18 update");
    console.log(props)
  },
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
yugasun commented 2 years ago

@Relaxe111 you can refer to my project: https://github.com/yugasun/micro-frontend-starter