Asynchronous Execution of Laravel Elixir Commands
Asked Answered
D

1

7

I'm having some trouble with Laravel Elixir and working out in what order things are executed. I've been let to believe that chaining elixir calls will force them to execute synchronously but I've had issues where in certain circumstances certain commands don't seem to execute or appear to execute in an order that means they don't complete properly.

My first issue was that the dependencies.js file was never being versioned by the version() function until I swapped the two scripts() functions round, so the one for dependencies.js ran second.

Another issue is that when I run the tasks through the gulp function, the majority of times, the font-awesome fonts get copied to the build directory. However, when running gulp watch they often get omitted.

I'm able to work around both of these problems, but I keep seeing little things like this that make me think I don't fully understand execution order and subtleties around it. Does anyone know if I'm missing something obvious?

Thanks.

Here's my gulpfile.js code:

mix.sass("app.scss", 'public/css/', {
        includePaths: [paths.bootstrap + 'stylesheets/']
    })
    .scripts([
        'js/app.js'
    ], 'public/js/app.js', paths.assets)
    .scripts([
        // paths.jquery + "dist/jquery.js",
        paths.bootstrap + "javascripts/bootstrap.js",
        paths.assets + "js/freelancer/classie.js",
        paths.assets + "js/freelancer/cbpAnimatedHeader.js",
        paths.assets + "js/freelancer/jqBootstrapValidation.js",
        paths.assets + "js/freelancer/contact_me.js",
        paths.assets + "js/freelancer/freelancer.js"
    ], 'public/js/dependencies.js', './')
    .version([
        'public/js/dependencies.js',
        'public/js/app.js',
        'public/css/app.css'])
    .copy(paths.bootstrap + 'fonts/bootstrap/**', 'public/build/fonts')
    .copy(paths.assets + 'fonts/font-awesome/', 'public/build/fonts');
Dipody answered 12/2, 2015 at 12:0 Comment(2)
I think Elixir doesn't implement this feature yet. Take a look at this: github.com/gulpjs/gulp/blob/master/docs/recipes/…. I think you'll have to hack elixir or use just gulp to achieve what you want. You can take the Elixir ingredients and use them outside elixir.Bergin
It's because gulp executes things synchronously by default, however if you take a look at the elixir package.json file you'll see it has run-sequence in it. Use that to run your tasks async.Flitting
B
1

Laravel Elixir recently got updated and one of the first things this article talks about is the order of which things run.

It seems to have been a bug which is fixed in the latest version:

https://laravel-news.com/2015/07/laravel-elixir-version-3-is-released/

Broderickbrodeur answered 7/8, 2015 at 14:57 Comment(2)
Great, thanks. Seemed odd that it didn't but in the first place, but great news.Dipody
I feel like there's a difference between (1) ensuring tasks are triggered in sequence, and (2) ensuring that the prior task is complete before executing the next one in that sequence. It's totally possible to be sequential, yet asynchronous. Elixir v3 ensures that tasks run in sequence, but AFAICT, it doesn't address synchronicity, so some builds might still fail, depending on one's setup.Titty

© 2022 - 2024 — McMap. All rights reserved.