DEV Community

Discussion on: Why SvelteJS may be the best framework for new web devs

Collapse
 
vshareej profile image
SHAREEJ V K • Edited

If you are still looking for an option to import an external css please try this..
its a bit experimental but it works.

-- script--

import {onMount} from 'svelte';
let rootElement;

function loadExternalCss(parent, file) {
let element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css")
element.setAttribute("href", file)
parent.appendChild(element)
}

onMount(() => {
loadExternalCss(rootElement, './yourfolder/yourfile.css')
})

--/script--

in the html markup add this to the root element.

bind:this={rootElement}

this way you can even have css variables syntax support and also it works in svelte custom elements .