Laravel-mix: [Proposal] Use multiple extract

Created on 24 Jan 2017  路  4Comments  路  Source: JeffreyWay/laravel-mix

Hey !

With the arrival of HTTP2 it will be better to provide small chunk of assets instead of 1 or 2 big files.

It would be great if extract() can be called multiple times to create different bundle of assets. This can also be useful to lazy-load dependencies.

The api will looks like the code bellow.

mix.js('resources/assets/js/app.js', 'public/js')
  .extract(['vue', 'jquery'], 'bundle')
  .extract(['lodash'], 'anotherBundle')
  .sass('resources/assets/sass/app.scss', 'public/css')
enhancement

Most helpful comment

When using autoload, how do I specify in which extract the autoloaded package will be included?
Given the following configuration:

mix.sass('resources/assets/sass/app.scss', 'public/css')
    .js('resources/assets/js/app.js', 'public/js')
    .autoload({
        jquery: ['$', 'window.jQuery', 'jQuery']
    })
    .extract(['lodash', 'jquery', 'vue', 'axios', 'sweetalert2', 'pikaday'], 'js/vendor')
    .extract(['trumbowyg'], 'js/editor')
    .copy('node_modules/trumbowyg/dist/ui/icons.svg', 'public/img/icons.svg')
    .version();

What happens, is that jQuery gets included in the editor package, which is not what I want. Is my configuration wrong or is this a problem with Mix?

All 4 comments

Thanks ! 鉂わ笍

When using autoload, how do I specify in which extract the autoloaded package will be included?
Given the following configuration:

mix.sass('resources/assets/sass/app.scss', 'public/css')
    .js('resources/assets/js/app.js', 'public/js')
    .autoload({
        jquery: ['$', 'window.jQuery', 'jQuery']
    })
    .extract(['lodash', 'jquery', 'vue', 'axios', 'sweetalert2', 'pikaday'], 'js/vendor')
    .extract(['trumbowyg'], 'js/editor')
    .copy('node_modules/trumbowyg/dist/ui/icons.svg', 'public/img/icons.svg')
    .version();

What happens, is that jQuery gets included in the editor package, which is not what I want. Is my configuration wrong or is this a problem with Mix?

It would not work with versioning because manifest.js file creates only for the last vendor.js bundle and works only with last bundle.
If someone have solution for this, please notify me..

It would not work with versioning because manifest.js file creates only for the last vendor.js bundle and works only with last bundle.
If someone have solution for this, please notify me..

@Spartaques Splitting each build into it's own webpack.mix file seems like a possible solution, though not ideal

http://www.compulsivecoders.com/tech/how-to-build-multiple-vendors-using-laravel-mix/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mstralka picture mstralka  路  3Comments

amin101 picture amin101  路  3Comments

nezaboravi picture nezaboravi  路  3Comments

Cheddam picture Cheddam  路  3Comments

terion-name picture terion-name  路  3Comments