JavaScript Module Loading Possibly Broken
See original GitHub issueHi Jeffrey (and others),
Love your work.
Replacing Bootstrap with Foundation in Elixir works great, but the same swap does not work in Mix. I’ve spent over 8 hours trying to figure out why before bugging you here.
I’ve created a simple modification to your laravel-mix-example that illustrates the issue.
Trying to run the resulting js results in the error foundation is not a function
, because the Foundation code has not been ran at all (and so $.fn.foundation
has not been defined):
As best I can tell, the module loader in Elixir generates strings like so:
It appears to do this with some kind of experimental loader called buble-loader
. The eval()
call ensures the code gets ran.
Mix, on the other hand, uses perhaps a different Babel loader, resulting in actual code instead of a string:
For some reason, the jQuery plugin is never registered, it’s as if it’s dealing with a different jQuery instance?
Several others are having the same issue.
Thanks in advance for any guidance.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (1 by maintainers)
Top GitHub Comments
@JVMartin - Maybe. I like Buble a lot. I’m not sure if it’s related in this case, though.
We’re you using
mix.webpack()
with Laravel Elixir? Ormix.scripts()
?Webpack has always been confusing, when it comes to jQuery plugins. But I’d like to get this all figured out so that people don’t even have to think about it.
I was able to get it working by:
mix.autoload({})
to yourwebpack.mix.js
file.npm install script-loader
But, yeah, it really sucks that this is required. There’s a big thread on Foundation’s GitHub about it: https://github.com/zurb/foundation-sites/issues/7386
@JeffreyWay Thanks for the
mix.autoload({})
tip. That worked perfectly for me, from a fresh Laravel 5.4 install with Laravel Mix.For others, my relevant files are below (with a little experiment to prove the event binding works).
boostrap.js
app.js
webpack.mix.js