Load ressources from a composer package

Hi guys,

Silly question of the day: I am trying to include a swiper js library in my bedrock project. I thought it might be a good idea to check whether it is available on Packagist to include it in my project libraries.
I found it (nolimits4web/swiper - Packagist), included it with my composer.json and got stuck in the following step: load the js files in my theme

I tried to load with a classic enqueue script but can’t manage to build the path to the vendor dir. As I am not very familiar with Composer yet, I thought I might be missing something, any ideas?

Thanks for the help,

Cheers,

Philippe

You can add(import) it to your “main.js” file in themes/your-theme/resources/assets/scripts/main.js

By adding,
=> import ‘swiper/src/swiper.js’;

Hope this helps…:+1:

Composer is for managing PHP packages. It looks like Swiper is a JavaScript library, so it might make more sense to install it with yarn or npm in your theme. Then you should be able to import or require it in your theme’s JavaScript and it’ll get pulled in by the build process. The docs have a little more information about how this process works: https://roots.io/sage/docs/theme-development-and-building/

Hi @PrecisionCoder13,

Thanks for the tip. I’ll try this approach !

Hi @alwaysblank ,

It makes sense indeed. We are not using Sage yet but it’s in the roadmap.

Thanks guys
Phil

This topic was automatically closed after 42 days. New replies are no longer allowed.