-
I've noticed that the WASM file is served from https://www.jsdelivr.com/ when using I also see that there's a static method |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I have the same question about the import { DotLottie } from '@lottiefiles/dotlottie-web';
import lottieWasmUrl from '@lottiefiles/dotlottie-web/dist/dotlottie-player.wasm'; // this is loaded as a url by the bundler
export function setLottieWasmUrl() {
DotLottie.setWasmUrl(lottieWasmUrl);
} I was trying to use it on the component level and when bootstrapping the application but every time I get the WASM file loaded from the jsdelivr.com. I'm using the following versions:
|
Beta Was this translation helpful? Give feedback.
-
We currently do not have a self-contained bundle that embeds the WASM file within the JavaScript, making it self-contained. The downside of this approach is the increased JavaScript bundle size, which could reach approximately 1 MB. To keep the bundle size smaller, we preferred shipping the WASM file independently and asynchronously loading it from the CDN (jsdelivr). As a fallback, we also added unpkg CDN. If you want to self-host the WASM file, you can use Using as a React Componentimport { DotLottie } from "@lottiefiles/dotlottie-web";
import wasmUrl from "@lottiefiles/dotlottie-web/dist/dotlottie-player.wasm?url";
import { useRef, useEffect } from "react";
// Set the WASM URL
DotLottie.setWasmUrl(wasmUrl);
function DotLottiePlayer() {
const ref = useRef<HTMLCanvasElement>(null);
useEffect(() => {
new DotLottie({
canvas: ref.current!,
src: "https://lottie.host/242ebeec-6277-4937-afa6-3a1f9f54f0c0/UFK246mvwd.lottie",
autoplay: true,
loop: true,
});
}, []);
return (
<canvas
ref={ref}
style={{
width: 300,
height: 300,
}}
/>
);
}
export default DotLottiePlayer; Using as a Web Componentimport { DotLottie } from "@lottiefiles/dotlottie-web";
import wasmUrl from "@lottiefiles/dotlottie-web/dist/dotlottie-player.wasm?url";
// Set the WASM URL
DotLottie.setWasmUrl(wasmUrl);
class DotLottiePlayer extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.canvas = document.createElement("canvas");
this.canvas.style.width = "300px";
this.canvas.style.height = "300px";
this.shadowRoot.appendChild(this.canvas);
}
static get observedAttributes() {
return ["src", "loop", "autoplay"];
}
attributeChangedCallback(name, oldValue, newValue) {
if (name === "src" || name === "loop" || name === "autoplay") {
this.loadAnimation();
}
}
connectedCallback() {
this.loadAnimation();
}
loadAnimation() {
const src = this.getAttribute("src");
const loop = this.getAttribute("loop") === "true";
const autoplay = this.getAttribute("autoplay") === "true";
new DotLottie({
canvas: this.canvas,
src: src,
autoplay: autoplay,
loop: loop,
});
}
}
customElements.define("dotlottie-player", DotLottiePlayer); |
Beta Was this translation helpful? Give feedback.
@AlanBreck @miszo This update has landed in
dotlottie-react@0.6.0
anddotlottie-wc@0.2.0
, please have a look and let me know