I basically used a .js file that I created in a Laravel 5.1 Project and that was now upgrade to Laravel 5.4.
In Laravel 5.1 we had elixer and the file was compress as expected.
Now with laravel-mix the fill is also compress and put into public/js/
but the file is much larger because the hole jQuery Library is included.
I want to load jQuery seperate e.g. from a CDN!
mix.js('resources/assets/js/foo.js', 'public/js')
With this lines you can test it:
// resources/assets/js/foo.js
$(document).ready(function(){
$('#foo').removeStyle('bar');
});
this is also do the same (including jQuery):
// resources/assets/js/foo.js
+function ($) {
$(document).ready(function(){
$('#foo').removeStyle('bar');
});
}(jQuery);
laravel-mix: v0.8.1
Node.js: v6.9.5 (latest LTS)
yarn: v0.20.3
Perhaps I don't understand... but just comment out this line:
https://github.com/laravel/laravel/blob/master/resources/assets/js/bootstrap.js#L10
@JVMartin every other file in /resources/assets/js/ that comes with a fresh installation do not exist in my case. So if this line would exit it would make more sense.
Based on the idea that I could load jQuery via a CDN I tried to remove the jQuery package. Now if I run the mix it exits with the error:
ERROR Failed to compile with 1 errors
This dependency was not found in node_modules:
* jquery
Did you forget to run npm install --save for it?
Commenting out this lines in the config file will do it but I'm not sure if this is really the way it is supposed to work, copy the hole config file just to remove view lines
// [email protected]/setup/webpack.config.js Line 295-299
new webpack.ProvidePlugin(Mix.autoload || {
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery'
}),
@stefanpolzer i have exactly ur case, however this happened when i tried to use mix in v5.3 installation. https://github.com/JeffreyWay/laravel-mix/issues/285#issuecomment-277307910
but now with fresh install of v5.4 and moved all my files to this new copy, i dont get the jquery issue anymore, so to disable jquery in webconfig
1- remove the jquery dependency from package.json
2- remove window.$ = window.jQuery = require('jquery'); from bootstrap.js
mix.autoload({});
docs: https://github.com/JeffreyWay/laravel-mix/blob/master/docs/autoloading.md
@QWp6t i believe this is an alt to including the window.$ = window.jQuery = require('jquery'); in bootstrap.js
This snippet specifies that Webpack should prepend var $ = require('jquery') to every location that it encounters either the global $ identifier, or window.jQuery. Nifty!
@QWp6t I do not have any bootstrap.js with the window.$ = window.jQuery = require('jquery');
But mix.autoload({}); in the webpack.mix.js file do the trick for me ....
Would be nice if this finds his way int the Laravel Docs
Most helpful comment
docs: https://github.com/JeffreyWay/laravel-mix/blob/master/docs/autoloading.md