Learn how to import CSS from node_modules into Svelte components.
Here’s how you import a CSS file from node_modules
in a Svelte component.
npm i rollup-plugin-css-only
rollup.config.js
. This will tell rollup to read the CSS imports and write them in a file called vendor.css
.+ import css from 'rollup-plugin-css-only';
export default {
input: 'src/main.js',
output: { ... },
plugins: [
+ css({ output: 'public/build/vendor.css' }),
svelte({
...
}),
...
};
index.html
. <html lang="en">
<head>
...
+ <link rel='stylesheet' href='/build/vendor.css'>
...
<script defer src='/build/bundle.js'></script>
</head>
<body>
</body>
</html>
App.svelte
. It’s not necessary to use the full path to node_modules
.<script>
+ import 'notyf/notyf.min.css';
export let name;
</script>
<main> <h1> Hello {name}! </h1> </main>
<style> h1 { color: #ff3e00; } </style>
Free Resources