I'm already familiar with laravel 5.1 mix (elixir), and recently I decided to test laravel 5.4 mix.
I mixed my libs on vendors files.
mix
.styles([
'./node_modules/bootstrap/dist/css/bootstrap.css',
'./node_modules/font-awesome/css/font-awesome.css'
], 'public/css/vendor.css')
.js([
'./node_modules/jquery/dist/jquery.js',
'./node_modules/bootstrap/dist/js/bootstrap.js',
], 'public/js/vendor.js')
.disableNotifications()
.version();
And included vendor on my page.
<script src="{{ mix('js/vendor.js') }}" type="text/javascript" charset="utf-8" async defer></script>
But, when I want use jQuery I have this error on image below. Before, in the laravel 5.1 I did exactly that way.
What do I have to do?
There is three way you can use jquery in laravel 9 you can use cdn or download jquery and import in laravel project or you can use jquery via npm.
jQuery is already included in this version of laravel as a dev dependency. This first command will install the dependencies. jquery will be added.
Laravel Mix, a package developed by Laracasts creator Jeffrey Way, provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors. In other words, Mix makes it a cinch to compile and minify your application's CSS and JavaScript files.
It should be in the root folder of your project, look at the laravel repo here.
Just uncomment this line in your assets/js/bootstrap.js
file:
window.$ = window.jQuery = require('jquery');
And make sure to require the bootstrap file in your assets/js/app.js
like this:
require('./bootstrap');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With