Im using require to include Javascript plugins for my project, but for some reason, the plugins cant be found by the browser. Starting npm run dev will compile all the scripts I need(scripts also located in the compiled file), but when running the project in the browser, it simply wont work.
[Vue warn]: Error in mounted hook: "TypeError: $(...).datepicker is not a function"
Here my files:
app.js
require('./bootstrap');
window.Vue = require('vue');
Vue.component('example-component', require('./components/ExampleComponent.vue'));
new Vue({
el: '#app',
mounted: function() {
$( "#datepicker" ).datepicker();
}
});
bootstrap.js
window._ = require('lodash');
try {
window.$ = window.jQuery = require('jquery');
require('bootstrap');
window.datepicker = require('jquery-datepicker');
} catch (e) {}
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
webpack.mix.js
let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Can anybody help me?