Created
June 28, 2014 14:47
-
-
Save manar007/7ce4dd0bdd9b76edb2ea to your computer and use it in GitHub Desktop.
gulp file configuration example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by narek.mamikonyan on 6/26/2014. | |
*/ | |
var config = { | |
srcDir: "src", | |
distDir: "dist", | |
tmpDir: ".tmp" | |
}; | |
var runSequence = require('run-sequence'); | |
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var clean = require('gulp-clean'); | |
var less = require('gulp-less'); | |
var connect = require('gulp-connect'); | |
var typescript = require('gulp-tsc'); | |
var path = require('path'); | |
var rename = require('gulp-rename'); | |
var minifyCSS = require('gulp-minify-css'); | |
var bower = require('gulp-bower'); | |
// clean tmp | |
gulp.task('clean-tmp',function(){ | |
return gulp.src(config.tmpDir, {read: false}) | |
.pipe(clean()); | |
}); | |
// clean dist | |
gulp.task('clean-dist',function(){ | |
return gulp.src(config.distDir, {read: false}) | |
.pipe(clean()); | |
}); | |
// clean all | |
gulp.task('clean-all',['clean-tmp','clean-dist']); | |
// bower files | |
gulp.task('bower', function() { | |
return bower(); | |
}); | |
// less | |
gulp.task('compile_less', function () { | |
gulp.src(config.srcDir+'/app/styles/style.less') | |
.pipe(less({})) | |
.pipe(gulp.dest(config.distDir + '/css')) | |
.pipe(rename('style.min.css')) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest(config.distDir + '/css')); | |
}); | |
// typescript | |
gulp.task('compile_ts', function(){ | |
gulp.src([config.srcDir + '/app/app.ts']) | |
.pipe(typescript({ | |
out: 'all.js', | |
emitError: false | |
})) | |
.pipe(gulp.dest('dist')) | |
.pipe(rename('all.min.js')) | |
.pipe(uglify({ | |
mangle: false | |
})) | |
.pipe(gulp.dest('dist')) | |
}); | |
// concat | |
gulp.task('concat-main', function() { | |
gulp.src(config.tmpDir + '/js/**/*.js') | |
.pipe(concat('all.js')) | |
.pipe(gulp.dest(config.distDir + '/js')) | |
}); | |
//connect | |
gulp.task('connect', function() { | |
function mountFolder(connect, dir) { | |
return connect.static(require('path').resolve(dir)); | |
}; | |
connect.server({ | |
livereload: true, | |
port: 8000, | |
tmpdir: config.tmpDir, | |
middleware: function (connect) { | |
return [ | |
function (req, res, next) { | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Allow-Headers', '*'); | |
res.setHeader('Access-Control-Allow-Credentials', 'true'); | |
res.setHeader('X-SERVED-BY', 'Site Name'); | |
next(); | |
}, | |
mountFolder(connect, 'dist'), | |
mountFolder(connect, 'node_modules'), | |
mountFolder(connect, 'src'), | |
mountFolder(connect, 'bower_components') | |
] | |
} | |
}); | |
}); | |
//watch | |
gulp.task('watch', function() { | |
gulp.watch(config.distDir+'/**/*.*', ['reload']); | |
}); | |
gulp.task('reload', function () { | |
gulp.src('app/**/*.*') | |
.pipe(connect.reload()); | |
}); | |
/// *** DEFAULT *** //// | |
gulp.task('default',function(){ | |
runSequence('clean-all',[ | |
'bower', | |
'compile_ts', | |
'compile_less' | |
],'connect','watch' , function(){ | |
gulp.watch(config.srcDir+'/**/*.ts', ['compile_ts']); | |
gulp.watch(config.srcDir+'/app/styles/**/*.less', ['compile_less']); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment