Last active
August 29, 2015 14:03
-
-
Save choffmeister/b9d11a579bc8ea62b3b7 to your computer and use it in GitHub Desktop.
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
var argv = require('yargs').argv, | |
bower = require('main-bower-files'), | |
coffee = require('gulp-coffee'), | |
concat = require('gulp-concat'), | |
connect = require('connect'), | |
filter = require('gulp-filter'), | |
gif = require('gulp-if'), | |
gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
jade = require('gulp-jade'), | |
less = require('gulp-less'), | |
livereload = require('gulp-livereload'), | |
proxy = require('proxy-middleware'), | |
rename = require('gulp-rename'), | |
rewrite = require('connect-modrewrite'), | |
uglify = require('gulp-uglify'), | |
url = require('url'); | |
var config = { | |
debug: !argv.dist, | |
src: 'app/', | |
dest: 'target/', | |
port: 9000 | |
}; | |
gulp.task('jade', function () { | |
return gulp.src(config.src + '**/*.jade') | |
.pipe(jade({ pretty: config.debug })) | |
.on('error', function (err) { | |
gutil.log(err.message); | |
gutil.beep(); | |
this.end(); | |
}) | |
.pipe(gulp.dest(config.dest)) | |
.pipe(livereload({ auto: false })); | |
}); | |
gulp.task('less', function () { | |
return gulp.src(config.src + 'styles/main.less') | |
.pipe(less({ compress: !config.debug })) | |
.on('error', function (err) { | |
gutil.log(err.message); | |
gutil.beep(); | |
this.end(); | |
}) | |
.pipe(rename('styles/main.css')) | |
.pipe(gulp.dest(config.dest)) | |
.pipe(livereload({ auto: false })); | |
}); | |
gulp.task('coffee', function () { | |
return gulp.src(config.src + 'scripts/**/*.coffee') | |
.pipe(coffee({ bare: false })) | |
.on('error', function (err) { | |
gutil.log(err); | |
gutil.beep(); | |
this.end(); | |
}) | |
.pipe(concat('scripts/app.js')) | |
.pipe(gif(!config.debug, uglify())) | |
.pipe(gulp.dest(config.dest)) | |
.pipe(livereload({ auto: false })); | |
}); | |
gulp.task('vendor', function () { | |
var filters = { | |
js: filter('**/*.js') | |
}; | |
return gulp.src(bower(), { base: 'bower_components' }) | |
.pipe(filters.js) | |
.pipe(gif(!config.debug, uglify({ preserveComments: 'some' }))) | |
.pipe(filters.js.restore()) | |
.pipe(gulp.dest(config.dest + 'vendor')); | |
}); | |
gulp.task('watch', ['build'], function () { | |
livereload.listen({ auto: true }); | |
gulp.watch(config.src + 'scripts/**/*.coffee', ['coffee']); | |
gulp.watch(config.src + 'styles/**/*.less', ['less']); | |
gulp.watch(config.src + '**/*.jade', ['jade']); | |
}); | |
gulp.task('connect', function (next) { | |
connect() | |
.use('/api', proxy(url.parse('http://localhost:8080/api'))) | |
.use(rewrite(['!(\.(html|css|js|png|jpg|gif|ttf|woff|svg|eot))$ /index.html [L]'])) | |
.use(connect.static(config.dest)) | |
.listen(config.port, next) | |
}); | |
gulp.task('build', ['coffee', 'less', 'jade', 'vendor']); | |
gulp.task('default', ['build', 'connect', 'watch']); |
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
{ | |
"name": "demo", | |
"version": "0.0.0-SNAPSHOT", | |
"devDependencies": { | |
"coffee-script": "^1.7.1", | |
"connect": "^2.21.0", | |
"connect-modrewrite": "^0.7.6", | |
"gulp": "^3.6.2", | |
"gulp-coffee": "^2.0.1", | |
"gulp-concat": "^2.2.0", | |
"gulp-filter": "^0.5.0", | |
"gulp-if": "^1.2.0", | |
"gulp-jade": "^0.6.0", | |
"gulp-less": "^1.2.3", | |
"gulp-livereload": "^2.1.0", | |
"gulp-rename": "^1.2.0", | |
"gulp-uglify": "^0.3.0", | |
"gulp-util": "^2.2.19", | |
"main-bower-files": "^1.0.0", | |
"proxy-middleware": "^0.5.0", | |
"yargs": "^1.2.1" | |
}, | |
"private": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment