How to improve a gulp rename and minify recipe?

I am using gulp to minify Javascript, but including it in handlebars.

So I have to rename the file to .js then minify it, and then rename it back to .hbs
I do this in 3 steps as follows:


gulp.task('footer-rename', function () {    
return gulp.src("/var/www/html/myfooddataNODE/views/partials/js/footerJS.hbs")
.pipe(concat('footer.js'))
  .pipe(gulp.dest("/var/www/html/myfooddataNODE/views/partials/js")); 
});

gulp.task('pack-footer-js', function () {    
   return gulp.src(['/var/www/html/myfooddataNODE/views/partials/js/footer.js'])
       .pipe(strip())
       .pipe(concat('footerMin.js'))
     .pipe(minify({ext:{min:'.js'},noSource: true}))
       .pipe(gulp.dest('/var/www/html/myfooddataNODE/views/partials/js'));
 });

 gulp.task('footer-rename-2', function () {    
   return gulp.src("/var/www/html/myfooddataNODE/views/partials/js/footerMin.js")
   .pipe(concat('footerMIN.hbs'))
     .pipe(gulp.dest("/var/www/html/myfooddataNODE/views/partials/js")); 
   });

Is there a way to combine these 3 steps into one?

Also, I may end up just using a .js file, but plan to use this same process to convert .hbs into .html and then back to .hbs

Thanks for any help! :slight_smile:

I’m not sure if that’s the ideal way to do things. I’d include the scripts with src attributes if possible. There is probably a way to inline them, but I’m not sure how to do it without making things convoluted. (Someone else here might have some ideas.)

It might be possible to have nginx do the minification:

I remember you said that you didn’t like Cloudflare, but they have an auto-minification feature that is just a click of a button. Just mentioning another option that might be simpler.

1 Like

Sounds good. Yeah, I will probably stop inlining. Right now I am just doing that with handlebars. I will look into Nginx. Thanks!