Gulp

GulpλŠ” μ‹œκ°„μ„ μ†Œλͺ¨ν•˜λŠ” 개발 업무 흐름을 μžλ™ν™”ν•˜κΈ° μœ„ν•œ λ„κ΅¬μž…λ‹ˆλ‹€.

μžμ„Έν•œ λ‚΄μš©μ€ gulpjs.com μ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ‹œμž‘ν•˜κΈ°

$ npm install gulp-cli -g
$ npm install gulp -D
$ touch gulpfile.js
$ gulp --help

gulpjs.com μ—μ„œ 발췌

CLI 도ꡬλ₯Ό μ„€μΉ˜ν•˜κ³ , νŒ¨ν‚€μ§€λ₯Ό μ„€μΉ˜ν•œ ν›„ gulpfile.js νŒŒμΌμ„ λ§Œλ“€μ–΄μ„œ μ‹œμž‘ν•©λ‹ˆλ‹€.

뭘 ν•  수 μžˆμ§€?

gulpλŠ” μž‘μ—… 흐름을 μ •μ˜ν•˜κ³ , μ •μ˜λœ μž‘μ—…μ„ μ‹€ν–‰ν•˜λŠ” λ„κ΅¬μž…λ‹ˆλ‹€.

μ–΄λ–»κ²Œ ν™œμš©ν•  것인지λ₯Ό μƒκ°ν•˜κ³ , ν•˜κ³  싢은 λ™μž‘μ„ κ΅¬ν˜„ν•΄ 놓은 ν”ŒλŸ¬κ·ΈμΈμ˜ 도움을 λ°›μœΌλ©΄ λŒ€λΆ€λΆ„μ˜ λΉŒλ“œ μž‘μ—…μ„ μžλ™ν™”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

예제

PGU & LESS

gulpjs.com 의 gulpfile.js 의 λ‚΄μš©κ³Ό 같이 pug νŒŒμΌμ—μ„œ html 을 μƒμ„±ν•˜κ³ , less νŒŒμΌμ—μ„œ css νŒŒμΌμ„ μƒμ„±ν•œ ν›„ μΆ•μ†Œ minifyν•˜λŠ” μž‘μ—…μ„ μ •μ˜ν•˜κ³  μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

var gulp = require('gulp');
var pug = require('gulp-pug');
var less = require('gulp-less');
var minifycss = reuqire('gulp-csso');

// html 처리 μž‘μ—…
gulp.task('html', function() {
    return gulp
        .src('client/templates/*.pug')
        .pipe(pug())
        .pipe(gulp.dest('build/html'));
});

// css 처리 μž‘μ—…
gulp.task('css', function() {
    return gulp
        .src('client/templates/*.less')
        .pipe(less())
        .pipe(minifycss())
        .pipe(gulp.dest('build/css'));
});

// κΈ°λ³Έ μž‘μ—…μœΌλ‘œ html μž‘μ—…, css μž‘μ—…μ„ 지정
gulp.task('default', ['html', 'css']);

Typescript

νƒ€μž…μŠ€ν¬λ¦½νŠΈλ₯Ό μ»΄νŒŒμΌν•΄μ„œ ν•„μš”ν•œ μœ„μΉ˜μ— 좜λ ₯ν•˜λŠ” μž‘μ—…μ„ gulp둜 μž‘μ„±ν•œ μ˜ˆμ œμž…λ‹ˆλ‹€.

[ProjectDir]/Scripts/**/*.ts νŒŒμΌμ„ μ»΄νŒŒμΌν•΄μ„œ [ProjectDir]/wwwroot/js/**/*.js 둜 좜λ ₯ν•©λ‹ˆλ‹€.

const gulp = require('gulp'),
    rename = require('gulp-rename2'),
    clean = require('gulp-clean'),
    uglify = require('gulp-uglify'),
    ts = require('gulp-typescript');

const wwwroot = './wwwroot/',
    sourceroot = './Scripts/';

const paths = {
    ts: sourceroot + '**/*.ts',
    tsDefinitionFiles: 'npm_modules/@types/**/*.d.ts',
    jsDest: `${wwwroot}js/`,
};

gulp.task('typescript', () => {
    var tsProject = ts.createProject('tsconfig.json');

    return gulp
        .src([paths.tsDefinitionFiles, paths.ts, '!' + paths.minJS], {
            base: '.',
        })
        .pipe(tsProject())
        .pipe(uglify())
        .pipe(
            rename((pathObj, file) => {
                return pathObj.join(
                    pathObj.dirname(file).replace(/^Scripts\/?\\?/, ''),
                    pathObj.basename(file),
                );
            }),
        )
        .pipe(clean({}))
        .pipe(gulp.dest(paths.jsDest));
});

gulp.task('default', ['typescript']);