Where do you try to use it? In a script tag in html or?
Using jQuery libraries w/ Vite
Hey everyone,
I want to switch some of our apps to use Vite instead of Mix. Unfortunately I can't figure out, how to correctly import the jQuery libraries. Here is the untouched app.js:
import $ from 'jquery';
window.$ = window.jQuery = $;
require('sticky-table-headers');
require('jquery.are-you-sure');
import 'select2';
require('select2/dist/js/i18n/de');
window.$.fn.select2.defaults.set('language', 'de');
window.$('.js-table').stickyTableHeaders({
fixedOffset: window.$('#navbar'),
cacheHeaderHeight: true,
});
window.$('.js-dirty-check').areYouSure();
window.$('.js-select').select2();
require(xxx) doesn't work, since Vite uses ES6 import; so I tried different ways of including the libraries: e.g.:
// ...
import 'sticky-table-headers';
// ...
npm run build shows no errors, but the console: Uncaught TypeError: Cannot read properties of undefined (reading 'fn'). (using $ within the console does work, so jQuery is imported correctly)
As I understand this, I just need to include the libraries (sticky-table-headers, are-you-sure and select2), they don't need to be compiled, just be copied over...
So: How do I just include those files? Is there a native Vite way of doing this or do I need a plugin?
Thanks in advance for your help!
Please or to participate in this conversation.