Jun 17, 2020
0
Level 6
How to compile boostrap and jQuery using laravel-mix?
I am trying to use Laravel-mix to compile bootstrap & popper into a single bootstrap-standalone.js file. Additionally, jQuery along with js-cookie into a vendors.js file. Finally, all js file located into resources/app into app.js.
I added the following code to my webpack.mix.js file
const mix = require('laravel-mix');
const glob = require("glob");
mix.js([
'node_modules/jquery/dist/jquery.min.js',
'node_modules/js.cookie/dst/cookie.js'
], 'vendors.js')
.js(glob.sync("resources/app/**/*.js"), 'app.js')
.js(['node_modules/popper.js/dist/umd/popper.js'].concat(glob.sync("node_modules/bootstrap/js/src/**/*.js")), 'bootstrap-standalone.js')
.sass('resources/scss/bootstrap-4.scss', 'bootstrap-standalone.css');
The resources/scss/bootstrap-4.scss has the following code
$red: #d9534f;
@import "~bootstrap/scss/bootstrap";
I included the files into my html like so
<link href="bootstrap-standalone.css" rel="stylesheet" type="text/css" async />
<link href="app.css" rel="stylesheet" type="text/css" async />
<script src="vendors.js"></script>
<script src="bootstrap-standalone.js" async></script>
<script src="app.js" async></script>
However, the app.js is throwing the following error
TypeError: $(...).toast is not a function
The file resources/app/display_alerts.js contains
$(function (e) {
$('.toast').toast('show');
});
Am I doing something wrong with generating the bootstrap-standalone.js and/or vendors.js? What is causing this issue?
Please or to participate in this conversation.