Reputation: 55
I want to import jquery-confirm in my Laravel Vite. It's a jquery plugin. When I use it like this
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js" type="module"></script>
<script type="module">
$(function() {
$.alert({
title: 'Alert!',
content: 'Simple alert!',
});
});
</script>
It works well, but when I want import it from vite it returns Error: Uncaught TypeError: $.alert is not a function
my app.js:
import jQuery from 'jquery';
window.jQuery = window.$ = jQuery;
require("jquery-confirm/dist/jquery-confirm.min.js")
I tried all these ways:
require("jquery-confirm/dist/jquery-confirm.min.js")
require("jquery-confirm");
await import("jquery-confirm");
import("jquery-confirm");
Upvotes: 1
Views: 196
Reputation: 1069
If you install jquery-confirm
using NPM, then you should be able to import it:
npm install jquery-confirm
Then:
import jquery from "jquery";
window.jQuery = window.$ = jquery;
import jQueryConfirm from "jquery-confirm";
window.jQuery.confirm = window.$.confirm = jQueryConfirm;
Upvotes: 1