在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):rogeriopvl/gulp-ejs开源软件地址(OpenSource Url):https://github.com/rogeriopvl/gulp-ejs开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-ejs
UsageFirst, install npm install --save-dev gulp-ejs Then, add it to your 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 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 objectThe 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 Async rendering (requires runtime support)Since ejs v2.5.8 added support for promise/async-await You can use async/await in your ejs templates by passing 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 foobar() %> APIejs(data, options)dataType: A hash object where each key corresponds to a variable in your template. Note: As of optionsType: A hash object for ejs options. For more info on Renaming file extensionsAs of version 4, the third api parameter Here's an example for template files with 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 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论