0

Hi im using gulp to automate my compiling of .ejs files into html files, but when gulp-ejs compiles the files, it out it as ejs. I thing i need to define the .html extension in the ejs() object, but I can get it to work.

This is what I got so far:

gulp.task('ejs', function(){
    return gulp.src('src/templates/**/*.ejs')
    .pipe(ejs())
    .pipe(gulp.dest('builds/dev/'))
});

I have also tried this:

gulp.task('ejs', function(){
    return gulp.src('src/templates/**/*.ejs')
    .pipe(ejs({setting: '.html'}))
    .pipe(gulp.dest('builds/dev/'))
});

Br M

mkelle
  • 214
  • 1
  • 3
  • 9

2 Answers2

5

You need to provide the ext option in your settings object like this:

gulp.task('ejs', function(){
  return gulp.src('src/templates/**/*.ejs')
   .pipe(ejs({}, {ext:'.html'}))
   .pipe(gulp.dest('builds/dev/'))
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
0

you just need to use (gulp-rename) plugin for greater then version 4

const ejs = require('gulp-ejs')
const rename = require('gulp-rename')
 
gulp.src('./templates/*.ejs')
  .pipe(ejs({ title: 'gulp-ejs' }))
  .pipe(rename({ extname: '.html' }))
  .pipe(gulp.dest('./dist'))
Ashish Saini
  • 190
  • 3
  • 11