Skip to content

Instantly share code, notes, and snippets.

@iktakahiro
Last active October 22, 2015 12:18
Show Gist options
  • Save iktakahiro/de1c4d6cc59db3e58e4b to your computer and use it in GitHub Desktop.
Save iktakahiro/de1c4d6cc59db3e58e4b to your computer and use it in GitHub Desktop.
EJS と gulp を利用した HTML の生成 ref: http://qiita.com/iktakahiro/items/8569ff9ec0158e518393
npm -g install gulp
npm install ejs gulp gulp-ejs gulp-plumber --save-dev
gulp.task('ejs', () => {
var json = JSON.parse(fs.readFileSync('./var.json'));
gulp.src(['./_page/*.ejs'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(ejs(json))
.pipe(gulp.dest('./_build/'));
});
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset=UTF-8">
<title><%= commonTitle %></title>
</head>
<body>
<%- include('../_layout/header') -%>
<h1>Index ページ</h1>
<p>ヘッダとフッタを include しています。</p>
<%- include('../_layout/footer') -%>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset=UTF-8">
<title>タイトルです</title>
</head>
<body>
<h1>Index ページ</h1>
<p>ヘッダとフッタを include しています。</p>
<div id="footer">&copy; 2015 eurie Inc.</div>
</body>
</html>
{
"commonTitle": "タイトルです"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment