I have 2 js files that I want to compile in Laravel Mix and be able to access variables.
mix.js([
'resources/js/dashboard/sidebar.js',
'resources/js/dashboard/app.js',
]).'public/js/app.js');
I want to be able to separate sidebar so that I don't write everything in 1 file.
In my app.js,
"use strict";
$(function(){
console.log("B");
console.log(Sidebar());
})
And in my sidebar.js
"use strict";
console.log("A");
var Sidebar = function() {
console.log("C")
// setup of the sidebar
});
However, I keep receiving:
jQuery.Deferred exception: Sidebar is not defined ReferenceError: Sidebar is not defined Uncaught ReferenceError: Sidebar is not defined
If I check the console.log dummy things, I get:
A
B
jQuery.Deferred exception: Sidebar is not defined ReferenceError: Sidebar is not defined
Uncaught ReferenceError: Sidebar is not defined
and never "C"
I also tried to remove sidebar.js from Laravel Mix part and do require('./sidebar.js)
but same issue persists. I also tried changing swapping them mix.js
In the compiled file, I have in this order:
$(function () {
Sidebar();
});
"use strict";
Sidebar = function () { ... }