Hi.
I have a project set up using Laravel 10 that in turn uses vite. I'm having a problem understanding the best approach to scripts for pages and importing js libraries such as moment or dayjs.
After installing through npm I have updated my app.js to import the library:
import './bootstrap';
import 'laravel-datatables-vite';
import dayjs from 'dayjs';
import Alpine from 'alpinejs';
import focus from '@alpinejs/focus';
window.Alpine = Alpine;
Alpine.plugin(focus);
Alpine.start();
app.js is loaded via the page. However when I try and access dayjs from within a script tag within the page I get an error: dayjs is not defined.
This then means that the import is not being made available to scripts outside of app.js I think. In which case how best do I ensure dayjs is available outside of the module?
I have tried adding window.DayJs = dayjs; but that fails if I try to use it in the script for example:
const date = new Date();
console.log(DayJs(date, 'd/m/Y'));
which comes up with an error DayJS is not defined
Not sure of the correct way to resolve
Thank you