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

Dont depend on root config for bundled css mounting #1

Open
ankarhem opened this issue Sep 20, 2022 · 1 comment
Open

Dont depend on root config for bundled css mounting #1

ankarhem opened this issue Sep 20, 2022 · 1 comment

Comments

@ankarhem
Copy link

Hey! Thanks for this example. An improvement I found was setting the base property in the vite config to dynamically mount / unmount the css link.

const baseUrl = import.meta.env.BASE_URL;

const mountCss = () => {
  try {
    const css = document.createElement('link');
    css.id = 'single-spa-application:@norce/layout:css';
    css.rel = 'stylesheet';
    css.href = `${baseUrl}bundle.css`;
    document.head.appendChild(css);
  } catch (e) {
    console.error(e);
  }
};
const unmountCss = () => {
  try {
    const css = document.getElementById(
      'single-spa-application:@norce/layout:css'
    );
    if (css) {
      document.head.removeChild(css);
    }
  } catch (e) {
    console.error(e);
  }
};

export const bootstrap = svelteLifecycles.bootstrap;
export const mount = (...props) => {
  mountCss();
  return svelteLifecycles.mount(...props);
};
export const unmount = (...props) => {
  unmountCss();
  return svelteLifecycles.unmount(...props);
};
@rajasegar
Copy link
Member

@ankarhem This is awesome, thanks for the improvement example

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

2 participants