본문 바로가기
javascript/gulp

[템플릿] gulp-ejs : 설치 및 gulpfile.js 설정

by by-choice 2021. 1. 9.

1. 설치

npm install --save-dev gulp-ejs

2. gulpfiles.js 설정

const gulp = require("gulp");
const ejs = require("gulp-ejs");

gulp.task('gulpEjs', function() {
    return gulp
    .src("./src/html/*")
    .pipe(ejs())
    .pipe(gulp.dest("./dist/html"))
});

gulp.task( "default", gulp.parallel("gulpEjs") );

2021/01/07 - [web/gulp] - gulp 설치 및 .src() .pipe() .dest() / 설명 수정 추가 :(

2021/01/09 - [web/gulp] - [템플릿] gulp-ejs : 사용법

3. 샘플: 사용법은 다음글에 :)

3-1-1. src > html > index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <%- include('./include/head.ejs', {
        title: "fresh-mint"
    }) %>
</head>
<body>
    body area
</body>
</html>

3-1-2. src > html > include > head.ejs

<title><%= title %></title>

3-2. gulp 실행

gulp

3-3. 결과물: dist > html > index.html 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fresh-mint</title>
</head>
<body>
    body area
</body>
</html>

댓글