LoginSignup
0
0

More than 5 years have passed since last update.

gulp + pug(jade)で静的ファイルをjsonで一気に書き出す

Last updated at Posted at 2018-10-02

出来たやつ

import rename from 'gulp-rename';

ar pageData = readConfig(`${CONFIG}/result.json`);
pageData = pageData.pages;
var tacks = [];
for (var key in pageData) {
    (function(key) {
        gulp.task(pageData[key].id, function() {
            return gulp.src(`${SRC}/jade/result/index.jade`)
                .pipe(jade({
                    locals: pageData[key],
                    pretty: true
                }))
                .pipe(rename("result/"+pageData[key].id + ".html")) //出力ファイル名を指定
                .pipe(gulp.dest(`${DEST}`)); //ファイル出力先を設定
        });
    })(key);
    tacks.push(pageData[key].id);
}

//その他のとまとめて
gulp.task('build', gulp.parallel('css', 'js', 'html', tacks));

json を読み込む

var pageData = require(`${SRC}/config/result.json`);

ファイルの名前を変更する

テンプレートの名前のままにするわけにはいかないから

import rename from require('gulp-rename');
.pipe(rename(pageData[key].id+".html"))

参考サイト

gulpinfoの書き方

リネームとか基本的なの

0
0
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
0
0