Skip to content

Commit

Permalink
Merge pull request #4515 from reactioncommerce/perf-4514-dancastellon…
Browse files Browse the repository at this point in the history
…-swiper-dynamic-import

#4514: Dynamically import Swiper to reduce client bundle size
  • Loading branch information
aldeed committed Aug 14, 2018
2 parents 3b0e3dc + cbe5f68 commit 06b71e5
Showing 1 changed file with 21 additions and 13 deletions.
@@ -1,5 +1,5 @@
import Swiper from "swiper";
import { Components } from "@reactioncommerce/reaction-components";
import Logger from "@reactioncommerce/logger";
import { $ } from "meteor/jquery";
import { Session } from "meteor/session";
import { Template } from "meteor/templating";
Expand Down Expand Up @@ -48,18 +48,26 @@ Template.openCartDrawer.onRendered(() => {

$("#cart-drawer-container").fadeIn(() => {
if (!swiper) {
swiper = new Swiper(".cart-drawer-swiper-container", {
direction: "horizontal",
setWrapperSize: true,
loop: false,
grabCursor: true,
slidesPerView: "auto",
wrapperClass: "cart-drawer-swiper-wrapper",
slideClass: "cart-drawer-swiper-slide",
slideActiveClass: "cart-drawer-swiper-slide-active",
pagination: ".cart-drawer-pagination",
paginationClickable: true
});
import("swiper")
.then((module) => {
const Swiper = module.default;
swiper = new Swiper(".cart-drawer-swiper-container", {
direction: "horizontal",
setWrapperSize: true,
loop: false,
grabCursor: true,
slidesPerView: "auto",
wrapperClass: "cart-drawer-swiper-wrapper",
slideClass: "cart-drawer-swiper-slide",
slideActiveClass: "cart-drawer-swiper-slide-active",
pagination: ".cart-drawer-pagination",
paginationClickable: true
});
return swiper;
})
.catch((error) => {
Logger.error(error.message, "Unable to load Swiper module");
});
}
});
});
Expand Down

0 comments on commit 06b71e5

Please sign in to comment.