Chris
Chris

Reputation: 3486

How to best combine assets using Laravel Mix?

I have a question regarding this scenario which is best explained with this code:

mix.js('resources/assets/js/frontend.js', 'public/js')
    .sass('resources/assets/sass/frontend.scss', 'public/css')
    .extract([
        'jquery',
        'bootstrap'
    ])
    .scripts([
        'resources/assets/vendor/constellation.min.js'
    ], 'public/js/all.js')
     .styles([
         'resources/assets/vendor/swiper/css/swiper.min.css',
         'resources/assets/css/styles.css'
     ], 'public/css/all.css');

As you can see I create a frontend.js, vendor.js, frontend.css, all.js, and all.css. Now, my question is:

How can I combine all.js/all.css to frontend.js/frontend.css?

Any pointers would be greatly appreciated!

Upvotes: 0

Views: 397

Answers (1)

TheAlexLichter
TheAlexLichter

Reputation: 7289

Instead of thinking on how to combine those assets through Laravel mix, you can simply import/require them through their own logics.

For the Javascript, your can use import (ES6) or require to include the other JS assets.

The same works with SASS/SCSS, which can import CSS through the equally named command.

Upvotes: 1

Related Questions