Answer the question
In order to leave comments, you need to log in
Am I including jquery libraries in Laravel mix correctly?
app.js is loaded on all pages
, and create.js or profile.js are additionally loaded only on those that I need.
1) Tell me if I'm using mix correctly?
2) Doesn't the line import $ from 'jquery' cause jquery to be included a second time?
app.js
profile.jswindow.$ = window.jQuery = require('jquery');
import $ from 'jquery';
window.$ = window.jQuery = $;
require('jquery-mask-plugin');
$(document).ready(function(){
$('#phone').mask('+9 (999) 999-9999');
});
import $ from 'jquery';
window.$ = window.jQuery = $;
window.repeatable = require("jquery.repeatable/jquery.repeatable.js");
import 'jquery-ui/ui/widgets/datepicker.js';
$('#expires_at').datepicker();
$(function() {
$(".form-account-warehouses-create .repeatable").repeatable();
});
mix
.setPublicPath('public/build')
.setResourceRoot('/build/')
.js('resources/js/app.js', 'js')
.js('resources/js/profile.js', 'js')
.js('resources/js/create.js', 'js')
.version();
Answer the question
In order to leave comments, you need to log in
A working version of connecting jQuery in your js file, which is compiled through mix.js, will be like this:
global.jquery = global.jQuery = global.$ = require('jquery');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question