Andi1982's avatar

Add third Party npm package css to Laravel Mix (lightbox2)

Hey, I try to add lightbox2 to my laravel 9 project. So I did

npm install lightbox2 --save

and in resources/js/app.js I added

require('lightbox2');

After "npm run dev" I got the javascript part into my public/js/app.js file.

But how can I add the lightbox CSS to my compiled or generated app.css ??? I have no experience with postCSS or mix. Hope somebody can help.

0 likes
3 replies
undeportedmexican's avatar

just assign the require to a variable. (That's how I do it).

app.css

window.lightbox = require('lightbox2')

Then on your code you can just use it globally:

lightbox.{method}
Andi1982's avatar

Hm, it did not work your way. I got the CSS imported now by adding a @import statement to

resources/css/app.css

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import 'lightbox2/dist/CSS/lightbox.css';

Don't know if it is the right way, but it works ...

1 like
undeportedmexican's avatar

@Andi1982 I'm so sorry... for some reason, I thought it was a Javascript library.

yes, the way you're doing it is right. (In my opinion)

Please or to participate in this conversation.