Skip to content

Commit

Permalink
feat: improving dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Jan 24, 2024
1 parent 08e1d1d commit 0224706
Show file tree
Hide file tree
Showing 36 changed files with 296 additions and 271 deletions.
93 changes: 47 additions & 46 deletions bundles/all/src/index.ts
@@ -1,50 +1,4 @@
import type { Engine } from "@tsparticles/engine";
import { initPjs } from "@tsparticles/pjs";
import { loadArrowShape } from "@tsparticles/shape-arrow";
import { loadBubbleEffect } from "@tsparticles/effect-bubble";
import { loadCanvasMaskPlugin } from "@tsparticles/plugin-canvas-mask";
import { loadCardsShape } from "@tsparticles/shape-cards";
import { loadCogShape } from "@tsparticles/shape-cog";
import { loadCurlNoisePath } from "@tsparticles/path-curl-noise";
import { loadCurvesPath } from "@tsparticles/path-curves";
import { loadEasingBackPlugin } from "@tsparticles/plugin-easing-back";
import { loadEasingCircPlugin } from "@tsparticles/plugin-easing-circ";
import { loadEasingCubicPlugin } from "@tsparticles/plugin-easing-cubic";
import { loadEasingExpoPlugin } from "@tsparticles/plugin-easing-expo";
import { loadEasingLinearPlugin } from "@tsparticles/plugin-easing-linear";
import { loadEasingQuartPlugin } from "@tsparticles/plugin-easing-quart";
import { loadEasingQuintPlugin } from "@tsparticles/plugin-easing-quint";
import { loadEasingSinePlugin } from "@tsparticles/plugin-easing-sine";
import { loadEmittersShapeCanvas } from "@tsparticles/plugin-emitters-shape-canvas";
import { loadEmittersShapePath } from "@tsparticles/plugin-emitters-shape-path";
import { loadEmittersShapePolygon } from "@tsparticles/plugin-emitters-shape-polygon";
import { loadExportImagePlugin } from "@tsparticles/plugin-export-image";
import { loadExportJSONPlugin } from "@tsparticles/plugin-export-json";
import { loadExportVideoPlugin } from "@tsparticles/plugin-export-video";
import { loadExternalParticleInteraction } from "@tsparticles/interaction-external-particle";
import { loadExternalPopInteraction } from "@tsparticles/interaction-external-pop";
import { loadFull } from "tsparticles";
import { loadGradientUpdater } from "@tsparticles/updater-gradient";
import { loadHeartShape } from "@tsparticles/shape-heart";
import { loadHsvColorPlugin } from "@tsparticles/plugin-hsv-color";
import { loadInfectionPlugin } from "@tsparticles/plugin-infection";
import { loadLightInteraction } from "@tsparticles/interaction-light";
import { loadMotionPlugin } from "@tsparticles/plugin-motion";
import { loadOrbitUpdater } from "@tsparticles/updater-orbit";
import { loadParticlesRepulseInteraction } from "@tsparticles/interaction-particles-repulse";
import { loadPathShape } from "@tsparticles/shape-path";
import { loadPerlinNoisePath } from "@tsparticles/path-perlin-noise";
import { loadPoissonDiscPlugin } from "@tsparticles/plugin-poisson-disc";
import { loadPolygonMaskPlugin } from "@tsparticles/plugin-polygon-mask";
import { loadPolygonPath } from "@tsparticles/path-polygon";
import { loadRoundedPolygonShape } from "@tsparticles/shape-rounded-polygon";
import { loadRoundedRectShape } from "@tsparticles/shape-rounded-rect";
import { loadSVGPath } from "@tsparticles/path-svg";
import { loadSimplexNoisePath } from "@tsparticles/path-simplex-noise";
import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
import { loadSpiralShape } from "@tsparticles/shape-spiral";
import { loadTrailEffect } from "@tsparticles/effect-trail";
import { loadZigZagPath } from "@tsparticles/path-zig-zag";

/**
* Loads the slime bundle with all plugins needed for running the tsParticles All package.
Expand All @@ -56,6 +10,53 @@ import { loadZigZagPath } from "@tsparticles/path-zig-zag";
* @param refresh -
*/
export async function loadAll(engine: Engine, refresh = true): Promise<void> {
const { initPjs } = await import("@tsparticles/pjs"),
{ loadFull } = await import("tsparticles"),
{ loadHsvColorPlugin } = await import("@tsparticles/plugin-hsv-color"),
{ loadEasingBackPlugin } = await import("@tsparticles/plugin-easing-back"),
{ loadEasingCircPlugin } = await import("@tsparticles/plugin-easing-circ"),
{ loadEasingCubicPlugin } = await import("@tsparticles/plugin-easing-cubic"),
{ loadEasingExpoPlugin } = await import("@tsparticles/plugin-easing-expo"),
{ loadEasingLinearPlugin } = await import("@tsparticles/plugin-easing-linear"),
{ loadEasingQuartPlugin } = await import("@tsparticles/plugin-easing-quart"),
{ loadEasingQuintPlugin } = await import("@tsparticles/plugin-easing-quint"),
{ loadEasingSinePlugin } = await import("@tsparticles/plugin-easing-sine"),
{ loadEmittersShapeCanvas } = await import("@tsparticles/plugin-emitters-shape-canvas"),
{ loadEmittersShapePath } = await import("@tsparticles/plugin-emitters-shape-path"),
{ loadEmittersShapePolygon } = await import("@tsparticles/plugin-emitters-shape-polygon"),
{ loadCanvasMaskPlugin } = await import("@tsparticles/plugin-canvas-mask"),
{ loadInfectionPlugin } = await import("@tsparticles/plugin-infection"),
{ loadMotionPlugin } = await import("@tsparticles/plugin-motion"),
{ loadPolygonMaskPlugin } = await import("@tsparticles/plugin-polygon-mask"),
{ loadSoundsPlugin } = await import("@tsparticles/plugin-sounds"),
{ loadExportImagePlugin } = await import("@tsparticles/plugin-export-image"),
{ loadExportJSONPlugin } = await import("@tsparticles/plugin-export-json"),
{ loadExportVideoPlugin } = await import("@tsparticles/plugin-export-video"),
{ loadExternalParticleInteraction } = await import("@tsparticles/interaction-external-particle"),
{ loadExternalPopInteraction } = await import("@tsparticles/interaction-external-pop"),
{ loadLightInteraction } = await import("@tsparticles/interaction-light"),
{ loadParticlesRepulseInteraction } = await import("@tsparticles/interaction-particles-repulse"),
{ loadGradientUpdater } = await import("@tsparticles/updater-gradient"),
{ loadOrbitUpdater } = await import("@tsparticles/updater-orbit"),
{ loadCurvesPath } = await import("@tsparticles/path-curves"),
{ loadCurlNoisePath } = await import("@tsparticles/path-curl-noise"),
{ loadPerlinNoisePath } = await import("@tsparticles/path-perlin-noise"),
{ loadPoissonDiscPlugin } = await import("@tsparticles/plugin-poisson-disc"),
{ loadPolygonPath } = await import("@tsparticles/path-polygon"),
{ loadSVGPath } = await import("@tsparticles/path-svg"),
{ loadZigZagPath } = await import("@tsparticles/path-zig-zag"),
{ loadSimplexNoisePath } = await import("@tsparticles/path-simplex-noise"),
{ loadBubbleEffect } = await import("@tsparticles/effect-bubble"),
{ loadArrowShape } = await import("@tsparticles/shape-arrow"),
{ loadCardsShape } = await import("@tsparticles/shape-cards"),
{ loadCogShape } = await import("@tsparticles/shape-cog"),
{ loadHeartShape } = await import("@tsparticles/shape-heart"),
{ loadPathShape } = await import("@tsparticles/shape-path"),
{ loadRoundedPolygonShape } = await import("@tsparticles/shape-rounded-polygon"),
{ loadRoundedRectShape } = await import("@tsparticles/shape-rounded-rect"),
{ loadSpiralShape } = await import("@tsparticles/shape-spiral"),
{ loadTrailEffect } = await import("@tsparticles/effect-trail");

initPjs(engine);

await loadFull(engine, false);
Expand Down
13 changes: 7 additions & 6 deletions bundles/basic/src/index.ts
@@ -1,10 +1,4 @@
import type { Engine } from "@tsparticles/engine";
import { loadBaseMover } from "@tsparticles/move-base";
import { loadCircleShape } from "@tsparticles/shape-circle";
import { loadColorUpdater } from "@tsparticles/updater-color";
import { loadOpacityUpdater } from "@tsparticles/updater-opacity";
import { loadOutModesUpdater } from "@tsparticles/updater-out-modes";
import { loadSizeUpdater } from "@tsparticles/updater-size";

/**
* Loads the slime bundle with all plugins needed for running the tsParticles Basic package.
Expand All @@ -16,6 +10,13 @@ import { loadSizeUpdater } from "@tsparticles/updater-size";
* @param refresh -
*/
export async function loadBasic(engine: Engine, refresh = true): Promise<void> {
const { loadBaseMover } = await import("@tsparticles/move-base"),
{ loadCircleShape } = await import("@tsparticles/shape-circle"),
{ loadColorUpdater } = await import("@tsparticles/updater-color"),
{ loadOpacityUpdater } = await import("@tsparticles/updater-opacity"),
{ loadOutModesUpdater } = await import("@tsparticles/updater-out-modes"),
{ loadSizeUpdater } = await import("@tsparticles/updater-size");

await loadBaseMover(engine, false);

await loadCircleShape(engine, false);
Expand Down
32 changes: 17 additions & 15 deletions bundles/confetti/src/confetti.ts
Expand Up @@ -8,23 +8,9 @@ import {
millisecondsToSeconds,
tsParticles,
} from "@tsparticles/engine";
import { type EmitterContainer, loadEmittersPlugin } from "@tsparticles/plugin-emitters";
import { ConfettiOptions } from "./ConfettiOptions.js";
import type { EmitterContainer } from "@tsparticles/plugin-emitters";
import type { IConfettiOptions } from "./IConfettiOptions.js";
import { loadBasic } from "@tsparticles/basic";
import { loadCardsShape } from "@tsparticles/shape-cards";
import { loadEmojiShape } from "@tsparticles/shape-emoji";
import { loadHeartShape } from "@tsparticles/shape-heart";
import { loadImageShape } from "@tsparticles/shape-image";
import { loadLifeUpdater } from "@tsparticles/updater-life";
import { loadMotionPlugin } from "@tsparticles/plugin-motion";
import { loadPolygonShape } from "@tsparticles/shape-polygon";
import { loadRollUpdater } from "@tsparticles/updater-roll";
import { loadRotateUpdater } from "@tsparticles/updater-rotate";
import { loadSquareShape } from "@tsparticles/shape-square";
import { loadStarShape } from "@tsparticles/shape-star";
import { loadTiltUpdater } from "@tsparticles/updater-tilt";
import { loadWobbleUpdater } from "@tsparticles/updater-wobble";

const defaultGravity = 9.81,
sizeFactor = 5,
Expand Down Expand Up @@ -113,6 +99,22 @@ async function initPlugins(engine: Engine): Promise<void> {

initializing = true;

const { loadEmittersPlugin } = await import("@tsparticles/plugin-emitters"),
{ loadMotionPlugin } = await import("@tsparticles/plugin-motion"),
{ loadCardsShape } = await import("@tsparticles/shape-cards"),
{ loadHeartShape } = await import("@tsparticles/shape-heart"),
{ loadImageShape } = await import("@tsparticles/shape-image"),
{ loadPolygonShape } = await import("@tsparticles/shape-polygon"),
{ loadSquareShape } = await import("@tsparticles/shape-square"),
{ loadStarShape } = await import("@tsparticles/shape-star"),
{ loadEmojiShape } = await import("@tsparticles/shape-emoji"),
{ loadRotateUpdater } = await import("@tsparticles/updater-rotate"),
{ loadLifeUpdater } = await import("@tsparticles/updater-life"),
{ loadRollUpdater } = await import("@tsparticles/updater-roll"),
{ loadTiltUpdater } = await import("@tsparticles/updater-tilt"),
{ loadWobbleUpdater } = await import("@tsparticles/updater-wobble"),
{ loadBasic } = await import("@tsparticles/basic");

await loadEmittersPlugin(engine, false);
await loadMotionPlugin(engine, false);
await loadCardsShape(engine, false);
Expand Down
17 changes: 9 additions & 8 deletions bundles/fireworks/src/fireworks.ts
Expand Up @@ -19,14 +19,6 @@ import {
} from "@tsparticles/engine";
import { FireworkOptions } from "./FireworkOptions.js";
import type { IFireworkOptions } from "./IFireworkOptions.js";
import { loadBasic } from "@tsparticles/basic";
import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
import { loadEmittersShapeSquare } from "@tsparticles/plugin-emitters-shape-square";
import { loadLifeUpdater } from "@tsparticles/updater-life";
import { loadRotateUpdater } from "@tsparticles/updater-rotate";
import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
import { loadTrailEffect } from "@tsparticles/effect-trail";

const minSplitCount = 2;

Expand Down Expand Up @@ -93,6 +85,15 @@ async function initPlugins(): Promise<void> {

initializing = true;

const { loadEmittersPlugin } = await import("@tsparticles/plugin-emitters"),
{ loadEmittersShapeSquare } = await import("@tsparticles/plugin-emitters-shape-square"),
{ loadSoundsPlugin } = await import("@tsparticles/plugin-sounds"),
{ loadRotateUpdater } = await import("@tsparticles/updater-rotate"),
{ loadDestroyUpdater } = await import("@tsparticles/updater-destroy"),
{ loadLifeUpdater } = await import("@tsparticles/updater-life"),
{ loadTrailEffect } = await import("@tsparticles/effect-trail"),
{ loadBasic } = await import("@tsparticles/basic");

await loadEmittersPlugin(tsParticles, false);
await loadEmittersShapeSquare(tsParticles, false);
await loadSoundsPlugin(tsParticles, false);
Expand Down
25 changes: 13 additions & 12 deletions bundles/full/src/index.ts
@@ -1,16 +1,4 @@
import type { Engine } from "@tsparticles/engine";
import { loadAbsorbersPlugin } from "@tsparticles/plugin-absorbers";
import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
import { loadEmittersShapeCircle } from "@tsparticles/plugin-emitters-shape-circle";
import { loadEmittersShapeSquare } from "@tsparticles/plugin-emitters-shape-square";
import { loadExternalTrailInteraction } from "@tsparticles/interaction-external-trail";
import { loadRollUpdater } from "@tsparticles/updater-roll";
import { loadSlim } from "@tsparticles/slim";
import { loadTextShape } from "@tsparticles/shape-text";
import { loadTiltUpdater } from "@tsparticles/updater-tilt";
import { loadTwinkleUpdater } from "@tsparticles/updater-twinkle";
import { loadWobbleUpdater } from "@tsparticles/updater-wobble";

/**
* Loads the full bundle with all plugins needed for running the tsParticles package.
Expand All @@ -22,6 +10,19 @@ import { loadWobbleUpdater } from "@tsparticles/updater-wobble";
* @param refresh -
*/
export async function loadFull(engine: Engine, refresh = true): Promise<void> {
const { loadDestroyUpdater } = await import("@tsparticles/updater-destroy"),
{ loadRollUpdater } = await import("@tsparticles/updater-roll"),
{ loadTiltUpdater } = await import("@tsparticles/updater-tilt"),
{ loadTwinkleUpdater } = await import("@tsparticles/updater-twinkle"),
{ loadWobbleUpdater } = await import("@tsparticles/updater-wobble"),
{ loadTextShape } = await import("@tsparticles/shape-text"),
{ loadExternalTrailInteraction } = await import("@tsparticles/interaction-external-trail"),
{ loadAbsorbersPlugin } = await import("@tsparticles/plugin-absorbers"),
{ loadEmittersPlugin } = await import("@tsparticles/plugin-emitters"),
{ loadEmittersShapeCircle } = await import("@tsparticles/plugin-emitters-shape-circle"),
{ loadEmittersShapeSquare } = await import("@tsparticles/plugin-emitters-shape-square"),
{ loadSlim } = await import("@tsparticles/slim");

await loadDestroyUpdater(engine, false);
await loadRollUpdater(engine, false);
await loadTiltUpdater(engine, false);
Expand Down
51 changes: 26 additions & 25 deletions bundles/slim/src/index.ts
@@ -1,29 +1,4 @@
import type { Engine } from "@tsparticles/engine";
import { loadBasic } from "@tsparticles/basic";
import { loadEasingQuadPlugin } from "@tsparticles/plugin-easing-quad";
import { loadEmojiShape } from "@tsparticles/shape-emoji";
import { loadExternalAttractInteraction } from "@tsparticles/interaction-external-attract";
import { loadExternalBounceInteraction } from "@tsparticles/interaction-external-bounce";
import { loadExternalBubbleInteraction } from "@tsparticles/interaction-external-bubble";
import { loadExternalConnectInteraction } from "@tsparticles/interaction-external-connect";
import { loadExternalGrabInteraction } from "@tsparticles/interaction-external-grab";
import { loadExternalPauseInteraction } from "@tsparticles/interaction-external-pause";
import { loadExternalPushInteraction } from "@tsparticles/interaction-external-push";
import { loadExternalRemoveInteraction } from "@tsparticles/interaction-external-remove";
import { loadExternalRepulseInteraction } from "@tsparticles/interaction-external-repulse";
import { loadExternalSlowInteraction } from "@tsparticles/interaction-external-slow";
import { loadImageShape } from "@tsparticles/shape-image";
import { loadLifeUpdater } from "@tsparticles/updater-life";
import { loadLineShape } from "@tsparticles/shape-line";
import { loadParallaxMover } from "@tsparticles/move-parallax";
import { loadParticlesAttractInteraction } from "@tsparticles/interaction-particles-attract";
import { loadParticlesCollisionsInteraction } from "@tsparticles/interaction-particles-collisions";
import { loadParticlesLinksInteraction } from "@tsparticles/interaction-particles-links";
import { loadPolygonShape } from "@tsparticles/shape-polygon";
import { loadRotateUpdater } from "@tsparticles/updater-rotate";
import { loadSquareShape } from "@tsparticles/shape-square";
import { loadStarShape } from "@tsparticles/shape-star";
import { loadStrokeColorUpdater } from "@tsparticles/updater-stroke-color";

/**
* Loads the slime bundle with all plugins needed for running the tsParticles Slim package.
Expand All @@ -35,6 +10,32 @@ import { loadStrokeColorUpdater } from "@tsparticles/updater-stroke-color";
* @param refresh -
*/
export async function loadSlim(engine: Engine, refresh = true): Promise<void> {
const { loadParallaxMover } = await import("@tsparticles/move-parallax"),
{ loadExternalAttractInteraction } = await import("@tsparticles/interaction-external-attract"),
{ loadExternalBounceInteraction } = await import("@tsparticles/interaction-external-bounce"),
{ loadExternalBubbleInteraction } = await import("@tsparticles/interaction-external-bubble"),
{ loadExternalConnectInteraction } = await import("@tsparticles/interaction-external-connect"),
{ loadExternalGrabInteraction } = await import("@tsparticles/interaction-external-grab"),
{ loadExternalPauseInteraction } = await import("@tsparticles/interaction-external-pause"),
{ loadExternalPushInteraction } = await import("@tsparticles/interaction-external-push"),
{ loadExternalRemoveInteraction } = await import("@tsparticles/interaction-external-remove"),
{ loadExternalRepulseInteraction } = await import("@tsparticles/interaction-external-repulse"),
{ loadExternalSlowInteraction } = await import("@tsparticles/interaction-external-slow"),
{ loadParticlesAttractInteraction } = await import("@tsparticles/interaction-particles-attract"),
{ loadParticlesCollisionsInteraction } = await import("@tsparticles/interaction-particles-collisions"),
{ loadParticlesLinksInteraction } = await import("@tsparticles/interaction-particles-links"),
{ loadEasingQuadPlugin } = await import("@tsparticles/plugin-easing-quad"),
{ loadEmojiShape } = await import("@tsparticles/shape-emoji"),
{ loadImageShape } = await import("@tsparticles/shape-image"),
{ loadLineShape } = await import("@tsparticles/shape-line"),
{ loadPolygonShape } = await import("@tsparticles/shape-polygon"),
{ loadSquareShape } = await import("@tsparticles/shape-square"),
{ loadStarShape } = await import("@tsparticles/shape-star"),
{ loadLifeUpdater } = await import("@tsparticles/updater-life"),
{ loadRotateUpdater } = await import("@tsparticles/updater-rotate"),
{ loadStrokeColorUpdater } = await import("@tsparticles/updater-stroke-color"),
{ loadBasic } = await import("@tsparticles/basic");

await loadParallaxMover(engine, false);

await loadExternalAttractInteraction(engine, false);
Expand Down

0 comments on commit 0224706

Please sign in to comment.