Can't get gulp-ejs to compile EJS to .html

3.2k Views Asked by At

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

2

There are 2 best solutions below

1
On

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/'))
});
0
On

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'))