thepsion5
548
10
Mix

Creating Multiple Separate Elixir Tasks?

Posted 3 years ago by thepsion5

I currently have a single elixir task that builds my javascript files and then compiles my javascript dependencies into a single file:

var elixir = require('laravel-elixir');
var publicDir = './public/js/';

elixir(function(mix)
{
    mix.browserify(['app.js'], publicDir + 'bundle.js')
    .scripts([
        'vendor/jquery.min.js',
        'vendor/react.min.js',
        'vendor/bootstrap.min.js'
        ], publicDir + 'vendor.js');
});

This is fine, but compiling the vendor scripts is unnecessary 99.9% of the time, since they rarely change. I'd much rather break this into two tasks, build and build-vendor, but I'm not sure how to do this with elixir.

My first thought is to create separate Gulp tasks that call the elixir methods, but obviously this won't work:

gulp.task('build', function() {
    elixir(function(mix)
    {
        mix.browserify(['app.js'], publicDir + 'bundle.js');
    });
});

gulp.task('build-vendor', function() {
    elixir(function(mix)
    {
        mix.scripts([
            'vendor/jquery.min.js',
            'vendor/react.min.js',
            'vendor/bootstrap.min.js'
            ], publicDir + 'vendor.js');
    });
});

I've poked around the elixir source code but I'm not familiar enough with the structure and dependencies to know much about what I'm looking at. Has anyone here done something similar? Can anyone provide guidance on where I should be looking or what I should be looking for?

Please sign in or create an account to participate in this conversation.