Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Install sweetalert2 via Laravel-Mix?

STEP1: In console/terminal.

npm install --save sweetalert2

STEP2: In app.scss add this line...

@import '~sweetalert2/src/sweetalert2.scss';

STEP3: In app.js add this line...

const swal = require('sweetalert2');

STEP4: In webpack.min.js...

mix.setPublicPath('public');
mix.js('resources/js/app.js', 'js');
mix.sass('resources/sass/app.scss', 'css');

STEP5: npm run dev

STEP6: Add app.js and app.css to HTML document

I got this error:

Uncaught ReferenceError: swal is not defined

What's the missing step?

like image 696
Areza Avatar asked Nov 27 '18 20:11

Areza


Video Answer


1 Answers

If you want to make it available anywhere you would have to tie it to the window:

const swal = window.swal = require('sweetalert2');

But a better way would be to include it in any file you use it in, the same way you did in app.js

like image 151
Jeff Avatar answered Sep 18 '22 06:09

Jeff