elqouent10's avatar

Running mix.version() inside Gulp Task

I am running a gulp task to copy all files with a .tpl.html recursively within a particular folder to the public folder. These html files will be used by AngularJS as templates. While doing this, I want to add all the file paths with a .tpl.html extension into an array, so that I can cache bust all of them.

var versionedFiles = [];

mix.task('copyHtmlTemplates', 'resources/assets/js/app/**/*.tpl.html');
gulp.task('copyHtmlTemplates', function(){
        gulp.src(['resources/assets/js/app/**/*.tpl.html'])
            .pipe(rename(function (path) {
                var fullPath = 'public/js/app/templates/' + path.dirname + '/' + path.basename + path.extname;
                versionedFiles.push(fullPath);
                return path;
              })
            )
            .pipe(gulp.dest('public/js/app/templates'))
            .on('end', function(){
        console.log("triggered"); //THIS SHOWS IN CONSOLE
        mix.version(versionedFiles);               //BUT THIS DOESN'T RUN
                mix.version([ 'public/css/app.css']); //BUT THIS DOESN'T RUN EITHER
        mix.version([ 'alskdflasdkj.css']); //MIX.VERSION DOESN'T WANT TO RUN!!!
            });
                       
    });

mix.version(versionedFiles);    //This runs, but it uses the array BEFORE the gulp task can append to it.

Does anyone know how to get mix.version to run after all gulp tasks have completed?

0 likes
2 replies
mehany's avatar

You can keep gulp tasks outside of Elixir and call gulp tasks inside the Elixir object like this

 elixir(function(mix) {
    mix.task('copyHtmlTemplates')
           .version([  /* files */ ])
    });
brian-lamb-software-engineer's avatar

To run mix inside a gulp task, you need to add in the elixir function. e.g. for your first mix task:

gulp.task('copy-html-templates', function () {
  elixir(function(mix) {
mix.task('copyHtmlTemplates', 'resources/assets/js/app/**/*.tpl.html');
   });
});

Please or to participate in this conversation.