- With rollup you can just import the css file like you will do for a
.js
module:
<script>
import { onMount } from "svelte";
import "swiper/swiper-bundle.min.css"; // <- just import your css
...
</script>
- For the navigation issue it's written in the swiper documentation:
By default Swiper exports only core version without additional modules (like Navigation, Pagination, etc.). So you need to import and configure them too:
// core version + navigation, pagination modules:
import Swiper, { Navigation, Pagination } from 'swiper';
// configure Swiper to use modules
Swiper.use([Navigation, Pagination]);
// init Swiper:
const swiper = new Swiper(...);
So finally, your component initialisation can be done like that:
<script>
import { onMount } from "svelte";
import "swiper/swiper-bundle.min.css";
import Swiper, { Navigation } from "swiper";
Swiper.use([Navigation]);
onMount(() => {
const swiper = new Swiper(".swiper-container", {
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
}
});
});
</script>
Here's the link for the codesandbox.