npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-ejs

v5.1.0

Published

A plugin for Gulp that parses ejs template files

Downloads

29,571

Readme

gulp-ejs NPM version Build Status Dependency Status

ejs plugin for gulp

Usage

First, install gulp-ejs as a development dependency:

npm install --save-dev gulp-ejs

Then, add it to your gulpfile.js:

var ejs = require("gulp-ejs")

gulp.src("./templates/*.ejs")
	.pipe(ejs({
		msg: "Hello Gulp!"
	}))
	.pipe(gulp.dest("./dist"))

Watch mode error handling (for gulp v3 or below)

If you want to use gulp-ejs in a watch/livereload task, you may want to avoid gulp exiting on error when, for instance, a partial file is ENOENT or an ejs syntax error.

Here's an example on how to make it work:

var ejs = require('gulp-ejs')
var log = require('fancy-log')

gulp.src('./templates/*.ejs')
	.pipe(ejs({
		msg: 'Hello Gulp!'
	}).on('error', log))
	.pipe(gulp.dest('./dist'))

This will make gulp log the error and continue normal execution.

Please note that you don't need to do this for Gulp v4.

Accessing the ejs object

The ejs object is also exported and you can use it to configure ejs:

const ejs = require('gulp-ejs')

ejs.__EJS__.fileLoader = function () { /* custom file loader */ }

Note: As of version 4, the exported ejs object was renamed from ejs to __EJS__.

Async rendering (requires runtime support)

Since ejs v2.5.8 added support for promise/async-await renderFile, you can now use this option with gulp-ejs v4.1.0.

You can use async/await in your ejs templates by passing { async: true } in the ejs options hash:

const ejs = require('gulp-ejs')

async function foobar() { /* async task */ }

gulp.src('./templates/*.ejs')
	.pipe(ejs({ foobar }, { async: true }))
	.pipe(gulp.dest('./dist'))

Then in your templates use await to call async functions. Here's an example:

<%= await foobar() %>

API

ejs(data, options)

data

Type: hash Default: {}

A hash object where each key corresponds to a variable in your template.

Note: As of v1.2.0, file.data is supported as a way of passing data into ejs. See this. If both file.data and data are passed, they are merged (data works as default for ejs options and file.data overrides it.)

options

Type: hash Default: {}

A hash object for ejs options.

For more info on ejs options, check the project's documentation.

Renaming file extensions

As of version 4, the third api parameter settings was removed. You can no longer provide an extension. This is because it falls out of the scope of gulp-ejs. So if you need to save the file with a different extension you can use gulp-rename.

Here's an example for template files with .ejs extension that are rendered into .html files:

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

License

MIT License