How to properly include particles.js in sage 9?

Hello :slight_smile: , I have been trying to integrate particlesjs for my custom theme but it wasn’t sucessfull.
I followed these two relevant threads https://discourse.roots.io/t/sage-9-external-js-not-defined/9860 and https://discourse.roots.io/t/which-way-is-the-correct-way-to-include-extra-js-files-in-sage-9/8926/2 to include particles js but it didn’t worked either.

Has anybody successfully integrated particlesjs in sage 9 theme ? Any help on this would be great. Thankyou

1 Like

Mhm this istn tested but I’d say:
yarn add particlesjs (or yarn add particles.js (https://yarnpkg.com/en/packages?q=particlesjs&p=1))

Then you have to import in common.js

import {particles} from 'particlesjs';

and


export default {
  init() {
particlesjs.init({
    selector: '.background'
  });
...

thanks , i tried that way it didn’t worked

I also have this problem.

yarn add particlesjs is a stripped down version of the other version. the solution above works (I removed the {} around particles).

I tried,
yarn add particles.js

with my home.js being this:

import {particlesJS} from 'particles.js';
export default {
  
  init() {
    // JavaScript to be fired on the home page
    particlesJS.load('particles-js', {JSON settings});

  },
  finalize() {
    // JavaScript to be fired on the home page, after the init JS
  },
};

But when i do that, and import in the home. I get load not defined.

Did you ever figure it out?