kekekiw123's avatar

Laravel mix put all js code inside app.js

I wonder if its possible to put everything inside the app.js file? I have a lot of files that I wont touch for a long time so I dont need to worrie about cache.

Right now I am doing this in my webpack.mix.js: mix.js('resources/assets/js/app.js', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .scripts([ 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js', 'resources/assets/js/libs/xxxx.js' ], 'public/js/all.js');

This will make two JS files: app.js and all.js. What I now want to do is to combine those files into one big file app.js. Is this possible with?:

mix.babel(['app.js', 'all.js'], 'app.js'); ?

0 likes
2 replies
Jaytee's avatar
Jaytee
Best Answer
Level 39

Well, I can say it is possible however, I strongly recommend you don't.

the libs Javascripts are likely not going to change frequently so if you combine it with your main javascript, you're just going to be busting the cache every time which means the whole lot needs to be reloaded. Not to mention, you'll need to compile the whole lot every time you make a change.

I suggest keeping the two files separate. That way, when you make a change, only the cache will bust for your main javascript stylesheet thus, faster loading times.

1 like

Please or to participate in this conversation.