简体   繁体   中英

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'); ?

You could put everything in the js() method and take advantage of it (as described here ):

mix.sass('resources/assets/sass/app.scss', 'public/css');

mix.js([
    'resources/assets/js/app.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',
    'resources/assets/js/libs/xxxx.js'
], 'public/js/all.js');

Try checking the documentation from the Laravel Mix repository on Github . There are some useful information and examples.

To combine .js files use mix.combine:

mix.combine(['one.js', 'two.js'], 'merged.js');

https://github.com/JeffreyWay/laravel-mix/blob/master/docs/concatenation-and-minification.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM