0

hi I am using laravel mix to compile all js file but the jquery is not working , even I use defer attribute, can anyone find what is the problem ? thanks

inside webpack.mix.js

// home page css
mix.styles([
    'public/app/css/bootstrap.min.css',
    'public/app/css/custom.css',
    'public/app/css/style.default.css',
    'public/app/css/font-awesome.all.css'
], 'public/css/base.css');


// admin css
mix.styles([
    'public/assets/css/sb-admin-2.min.css',
    'public/app/css/font-awesome.all.css'
], 'public/css/admin.base.css');

mix.autoload({
  jquery: ['$', 'window.jQuery', 'jQuery'],
});


// admin js
mix.js([
    'public/assets/js/jquery.min.js',
    'public/assets/js/bootstrap.bundle.min.js',
    'public/assets/js/jquery.easing.min.js',
], 'public/js/admin.lib.js');

inside blade

<!--   <script src="{{asset('assets/js/jquery.min.js')}}"></script>
  <script src="{{asset('assets/js/bootstrap.bundle.min.js')}}"></script>
  <script src="{{asset('assets/js/jquery.easing.min.js')}}"></script> -->



  <script src="{{asset('js/admin.lib.js')}}" defer></script>
  <script src="{{asset('assets/js/sb-admin-2.min.js')}}"></script>

I tried

mix.autoload({
  jquery: ['$', 'window.jQuery', 'jQuery'],
});

not working , tried to add $=jQuery inside lib.js but fails jquery was working

if I do not use the the compiled lib.js

what is the error I am facing is the $ not defined thanks btw , the css compilation is working though

4
  • Do your assets even compile? You have a weird path to your assets for a laravel project. Commented Aug 1, 2020 at 14:25
  • yes because i am cming from a beginer level hah Commented Aug 1, 2020 at 14:32
  • So they do compile? Commented Aug 1, 2020 at 14:40
  • yes i complied 'public/assets/js/jquery.min.js', 'public/assets/js/bootstrap.bundle.min.js', 'public/assets/js/jquery.easing.min.js', thos 3 to lib.js I can see lib.js was created Commented Aug 1, 2020 at 14:45

1 Answer 1

1
import $ from 'jquery';
window.$ = window.jQuery = $;

put those 2 command from the original jquery file at the begining solved my problem thanks

follow here https://medium.com/@nedsoft/how-to-add-jquery-ui-plugin-to-a-laravel-app-using-laravel-mix-e85bf0244fc1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.