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']);