Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Relaxe111 opened this issue Jul 21, 2022 · 3 comments
Open

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

Relaxe111 opened this issue Jul 21, 2022 · 3 comments

Comments

@Relaxe111
Copy link

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
Copy link
Collaborator

@Relaxe111
Copy link
Author

Relaxe111 commented Jul 22, 2022

@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
Copy link

yugasun commented Aug 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants