Combine assets with Laravel Mix

Last Updated at : December 3, 2017 By - Usama Muneer | 3325

    What’s Laravel Mix?

    Laravel Mix is a simple API built around Webpack to facilitate compiling of assets using several CSS and JS pre-processors.

    By default, your Laravel project’s webpack.mix.js contains the following code.

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

    What if you want to chain your included files along with that?

    Well there’s a simple solution to this using mix.combine method.

    For CSS files

    mix.combine([
        'resources/assets/css/styles.min.js',
        'resources/assets/css/main.min.js',
        'resources/assets/css/responsive.min.js',
    ], 'public/css/app.js');
    
    

    For JS files

    mix.combine([
        'resources/assets/js/libs/jquery-3.2.1.min.js',
        'resources/assets/js/libs/sweet_alert.min.js',
        'resources/assets/js/libs/main.js',
        'resources/assets/js/libs/functions.js'
    ], 'public/js/all.js');
    
    
    

    Well that’s it. Give it a try and see if that works out for you.

    If you have any queries regarding this blog, leave us a comment below. You can also follow us on Twitter.

    blog user
    Usama Muneer

    A web enthusiastic, self-motivated & detail-oriented professional Full-Stack Web Developer from Karachi, Pakistan with experience in developing applications using JavaScript, WordPress & Laravel specifically. Loves to write on different web technologies with an equally useful skill to make some sense out of it.

    Related Posts

    Lots of developers have been a fan of the short arrow function usage since their addition to programming languages. In JavaScript, it has helped make coding functions/closures more concise.

    To expand the business across the globe your application needs some specific changes. There are many ways to handle localization in an application but today we will have to look at how to handle it on frontend using ReactJs,i18next.

    Well, that was it, now we can simply jump to validating our form data with jQuery validate plugin & see how its done in no time.

    Vue.js has taken the front-end development world by storm over the last three years. The project, however, has been around much longer than that. It started in 2013 as a one-man project by Evan You.