I am no expert on webpack but I believe the default config excludes node_modules in *.js. That may be why. I usually copy any files I need from node-modules using the copy command before running other functions. It does add time but I get better results.
Mix in Laravel 5.4 with jQuery plugins
I've spent several hours trying to resolve this issue without any luck so perhaps someone could help.
I've set up my webpack.mix.js in the following way:
let mix = require('laravel-mix');
mix
.sass('./resources/assets/sass/admin/app.scss', './public/css/admin/app.css')
.sass('./resources/assets/sass/admin/login.scss', './public/css/admin/login.css')
.sass('./resources/assets/sass/front/app.scss', './public/css/app.css')
.js(
[
'./node_modules/cascading-dropdown/src/jquery.cascading-drop-down.js',
'./node_modules/ssd-form/src/jquery.ssd-form.js',
'./node_modules/ssd-confirm/src/jquery.ssd-confirm.js',
'./node_modules/simple-ajax-uploader/SimpleAjaxUploader.js',
'./node_modules/sortablejs/Sortable.js',
'./node_modules/swiper/dist/js/swiper.jquery.js',
'./node_modules/lightgallery/dist/js/lightgallery.js'
],
'./public/js/vendor.js'
)
.js(
[
'./resources/assets/js/app.js'
],
'./public/js/app.js'
)
.version();
My app.js file looks like so:
require('./bootstrap');
Vue.component('basket', require('./components/Basket.vue'));
Vue.component('pagination', require('./components/Pagination.vue'));
import Form from './core/Form';
import Focus from './core/Focus';
import Editor from './core/Editor';
import Sorter from './core/Sorter';
import Trigger from './core/Trigger';
import Gallery from './core/Gallery';
import SlideShow from './core/SlideShow';
import Navigation from './core/Navigation';
import Confirmation from './core/Confirmation';
import UploadManager from './core/Upload/UploadManager';
const app = new Vue({
el: '#app',
mounted() {
new Form();
new Focus();
new Editor();
new Sorter();
new Trigger();
new Gallery();
new SlideShow();
new Navigation();
new Confirmation();
new UploadManager();
}
});
When I run mix I get everything compiled without any errors, but when I preview the project in the browser it doesn't seem to be able to find the plugins which are included in the vendor.js file from within any of the classes i.e. Form.js:
class Form {
constructor() {
$('form[data-ajax-form]').ssdForm({
extendBehaviours: {
clickCallReload: function() {
window.location.reload(true);
}
}
});
}
}
export default Form;
I get
Uncaught TypeError: $(...).ssdForm is not a function
pointing to $('form[data-ajax-form]').ssdForm({}); call.
Also - my app.js contains jQuery and Sizzle multiple times - can't figure out where it comes from?
Thanks @ejdelmonico, but I'm afraid it wasn't that. I've updated the jQuery plugins by adding modular functionality and it seem to be working fine.
I've also removed all these plugins from mix.js([]) call and added them to mix.extract([]) together with vue and jquery.
Please or to participate in this conversation.