In webpack.mix.js, i use extract method like that:
mix.extract(['jquery', 'lodash'])
In main file app.js, i try to check them
console.log(_) <-- OK
console.log($) <-- Undefined
console.log(jQuery) <-- Undefined
window not show when use mix.autoload()In order to work for jQuery, i must use autoload method
mix.autoload({
jquery: ['$', 'window.jQuery', 'jQuery']
});
In main file app.js, i try to check them again
console.log($) <-- OK now
console.log(window) <-- ??? I can not find out `$` in browser console
Any help me explain those!? Thanks
@JeffreyWay
autoload() is using webpack ProvidePlugin internally.
extract() is just a way to keep your dependencies in a separate file, it does not autoload them.
ProvidePlugin will replace any occurrence with the specified module, in your case;
'$', 'window.jQuery', 'jQuery' will be replace by node_modules/jquery/main-file-specified-in-package.json module during webpack compilation.
Thank @ankurk91.
So why i add extract() for lodash, i dont use autoload, _ still be init in window?
Updated
I find out in lodash's source code window._ = lodash, maybe that help it auto init?!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I've been looking for it for a long time, but no one knows, including the person who made it.
If you are using laravel framework, there is one line in resources/js/bootstrap.js:
window._ = require('lodash');
Most helpful comment
I've been looking for it for a long time, but no one knows, including the person who made it.