Created
May 14, 2014 15:51
-
-
Save nnnnathann/2a78371f7b3ad4870e82 to your computer and use it in GitHub Desktop.
gulp-hang
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
/*jshint indent:2 */ | |
'use strict'; | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var fs = require('fs'); | |
var olive = require('oberd-olive'); | |
var livereload = require('gulp-livereload'); | |
var lr = require('tiny-lr'); | |
var server = lr(); | |
var oliveServer; | |
var config = { | |
port: 3000, | |
bowerDirectory: require('path').join(__dirname, 'app', 'bower_components'), | |
less: 'app/less/**/*.less', | |
fonts: [ | |
'app/bower_components/bootstrap-theme-oberd/fonts/**', | |
'app/bower_components/font-awesome/fonts/**' | |
], | |
images: [ | |
'app/bower_components/bootstrap-theme-oberd/images/**/*', | |
'app/images/**/*.{jpg,png,gif}' | |
], | |
svg: [ | |
'app/bower_components/bootstrap-theme-oberd/images/**/*.svg', | |
'app/images/**/*.svg' | |
], | |
html: [ | |
'app/*.html' | |
] | |
}; | |
var _ = require('lodash'); | |
if (fs.existsSync(__dirname + '/config.json')) { | |
_.extend(config, require('./config.json')); | |
} | |
// Clean | |
var clean = require('gulp-clean'); | |
gulp.task('clean', function () { | |
return gulp.src(['dist', '.tmp'], {read: false}).pipe(clean()); | |
}); | |
// CSS | |
var less = require('gulp-less'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
gulp.task('less', function () { | |
return gulp.src(config.less) | |
.pipe(less({ paths: [ config.bowerDirectory ] })) | |
.pipe(autoprefixer('last 1 version', '> 1%', 'ie 7')) | |
.pipe(gulp.dest('.tmp/styles')) | |
.pipe(livereload(server)); | |
}); | |
gulp.task('less-dist', function () { | |
return gulp.src(config.less) | |
.pipe(less({ paths: [ config.bowerDirectory ] })) | |
.pipe(autoprefixer('last 1 version', '> 1%', 'ie 7')) | |
.pipe(gulp.dest('dist/styles')); | |
}); | |
// Require.js | |
var rjs = require('requirejs'); | |
gulp.task('requirejs', function (cb) { | |
var config = { | |
mainConfigFile: 'app/scripts/require-config.js', | |
out: 'dist/scripts/app.js', | |
baseUrl: 'app/scripts', | |
logLevel: 3, | |
include: ['app'] | |
}; | |
rjs.optimize(config, function () { | |
cb(null); | |
}, cb); | |
}); | |
gulp.task('requireconfig', function () { | |
return gulp | |
.src('app/scripts/require-config.js') | |
.pipe(gulp.dest('dist/scripts')); | |
}); | |
gulp.task('requirelib', function () { | |
return gulp | |
.src('app/bower_components/requirejs/require.js') | |
.pipe(gulp.dest('dist/bower_components/requirejs')); | |
}); | |
// Images | |
var imagemin = require('gulp-imagemin'); | |
gulp.task('images', function () { | |
return gulp.src(config.images) | |
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })) | |
.pipe(gulp.dest('.tmp/images')) | |
.pipe(gulp.dest('dist/images')); | |
}); | |
var svgmin = require('gulp-svgmin'); | |
gulp.task('svg', function () { | |
return gulp.src(config.svg) | |
.pipe(svgmin()) | |
.pipe(gulp.dest('.tmp/images')) | |
.pipe(gulp.dest('dist/images')); | |
}); | |
// Combine HTML markup into files | |
var usemin = require('gulp-usemin'); | |
gulp.task('usemin', ['html-dist'], function () { | |
return gulp.src('app/*.html') | |
.pipe(usemin({ cssmin: true, htmlmin: true, jsmin: true })) | |
.pipe(gulp.dest('dist')); | |
}); | |
// Normal copy tasks | |
gulp.task('fonts', function () { | |
return gulp.src(config.fonts) | |
.pipe(gulp.dest('.tmp/fonts')) | |
.pipe(gulp.dest('dist/fonts')); | |
}); | |
gulp.task('html', function () { | |
return gulp.src(config.html) | |
.pipe(gulp.dest('.tmp')) | |
.pipe(livereload(server)); | |
}); | |
gulp.task('html-dist', function () { | |
return gulp.src(config.html).pipe(gulp.dest('dist')); | |
}); | |
var baseConfig = require('./olive.json'); | |
function serveOlive(root) { | |
baseConfig.root = root; | |
oliveServer = olive(baseConfig); | |
oliveServer.listen(config.port); | |
} | |
gulp.task('dev', ['fonts', 'less', 'html', 'svg', 'images'], function (next) { | |
server.listen(35729, function (err) { | |
if (err) { return console.error(err); } | |
gulp.watch(config.less, ['less']); | |
gulp.watch(config.html, ['html']); | |
next(); | |
}); | |
serveOlive(['app', '.tmp']); | |
}); | |
gulp.task('build', [ | |
'fonts', | |
'less-dist', | |
'svg', | |
'images', | |
'usemin', | |
'requirejs', | |
'requirelib', | |
'requireconfig' | |
], function () { | |
process.exit(0); | |
}); | |
gulp.task('dist', ['build'], function () { | |
serveOlive(['dist']); | |
}); | |
gulp.task('default', ['dev'], function () { | |
if (oliveServer) { | |
gutil.log('Olive is running: ', gutil.colors.underline.red.bold(oliveServer.listeningUrl(config.port))); | |
} | |
gutil.log('Watching files for changes...'); | |
}); |
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
[master][nathan@new-host:~/work/urs/applications/qsuite/client] | |
[10:47:55] 130 $ gulp requirejs | |
[gulp] Using gulpfile ~/work/urs/applications/qsuite/client/gulpfile.js | |
[gulp] Starting 'requirejs'... | |
[gulp] Finished 'requirejs' after 4.13 s | |
^C | |
[master][nathan@new-host:~/work/urs/applications/qsuite/client] | |
[10:50:24] 130 $ gulp -v | |
[gulp] CLI version 3.6.2 | |
[gulp] Local version 3.6.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment