LoginSignup
16
12

More than 5 years have passed since last update.

gulp-ejsはv3.0.0から引数の数が変わったらしいぞ

Last updated at Posted at 2017-02-23

どうやら最新版のgulp-ejs v3.0.0から新しいインタフェースに変わったようで引数の数が増えています。

githubのREADME.mdでいうとこの部分
https://github.com/rogeriopvl/gulp-ejs/commit/a53321155b9b7bfb38a669d1c5a6a15e0d9376f7#diff-04c6e90faac2675aa89e2176d2eec7d8R41

APIがejs(options, settings) から ejs(data, options, settings)に変わっています。今までejsに変数として渡すデータはoption引数の中に含まれていましたが、それをdata引数として切り分けたということですね。

Note: As of v2.0.0 the output file extension is no longer .html by default, you need to specify it, otherwise it will have the same extension of the input file.

また、こちらは以前(v2.0.0)からですが、変換後の拡張子を指定しないと.htmlではなく.ejsとして吐き出されます。

gulpfile.js
var gulp = require("gulp")
var ejs = require("gulp-ejs")

gulp.task("default", function() {
    gulp.src("./templates/*.ejs")
        .pipe(ejs({}, {}, {"ext": ".html"}))
        .pipe(gulp.dest("./dist"))
});

*余談ですが
今回この変更に気づいた理由としては、業務中に新しく入ってきたメンバーの方にgulpでビルドしてもhtmlが吐き出されないという指摘を受けたことがキッカケでした。
というのもpackage.jsonにversionを指定しておらず、それぞれの開発環境で異なったversionのgulp-ejsが入ってしまっていたという...
基本的なことですがパッケージのバージョンは指定しておく必要がありますね

16
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
12