Okay so I managed to do this in this way:
Service Component (contains loading JS static resource and related code)
import CONFETTI from '@salesforce/resourceUrl/Confetti';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
function loadConfetti(object) {
loadScript(object,CONFETTI);
}
function basicCannon() {
confetti({
particleCount: 100,
spread: 70,
origin: {
y: 0.6
}
});
}
function randomCannon() {
confetti({
angle: this.randomFun(55, 125),
spread: this.randomFun(50, 70),
particleCount: this.randomFun(50, 100),
origin: {
y: 0.6
}
});
}
function fireworks() {
var end = Date.now() + 15 * 1000;
let interval = setInterval(function() {
if (Date.now() > end) {
return clearInterval(interval);
}
confetti({
startVelocity: 30,
spread: 360,
ticks: 60,
origin: {
x: Math.random(),
y: Math.random() - 0.2
}
});
}, 200);
}
export {loadConfetti,basicCannon,randomCannon,fireworks};
And this would be used on the Lightning web component using IMPORT statement like
import confetti from 'c/confettiService';
And then use any method like
confetti.loadConfetti(this);
confetti.fireworks();