Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created December 29, 2013 14:37
Show Gist options
  • Save Sigmus/8171005 to your computer and use it in GitHub Desktop.
Save Sigmus/8171005 to your computer and use it in GitHub Desktop.
Migrating some configuration from Gruntfile.js to gulpfile.js
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var less = require('gulp-less');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var outDir = null;
var sources = {
scripts: './app/scripts/**/*.js',
less: './app/styles/**/*.less',
copy: [
{src: './app/templates/*', dest: ''},
{src: './app/images/*', dest: 'images'}
],
browserify: './app/scripts/main.js'
};
gulp.task('default', function () {
gulp.run('temp');
});
gulp.task('temp', function() {
outDir = './temp';
gulp.run('copy', 'less', 'jshint', 'browserify');
gulp.watch(sources.less, function() {
gulp.run('less');
});
sources.copy.forEach(function(item) {
gulp.watch(item.src, function() {
gulp.run('copy');
});
});
gulp.watch(sources.scripts, function() {
gulp.run('jshint');
});
gulp.watch(sources.browserify, function() {
gulp.run('browserify');
});
});
gulp.task('copy', function () {
sources.copy.forEach(function(item) {
gulp.src(item.src)
.pipe(gulp.dest(outDir + '/' + item.dest))
});
});
gulp.task('less', function () {
gulp.src(sources.less)
.pipe(less({compress: false}))
.pipe(gulp.dest(outDir + '/styles'));
});
gulp.task('jshint', function() {
gulp.src(sources.scripts)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
});
gulp.task('browserify', function() {
gulp.src(sources.browserify)
.pipe(browserify())
.pipe(concat('main.js'))
.pipe(gulp.dest(outDir + '/scripts/'))
});
@yocontra
Copy link

@Sigmus

  • Why are you copying to tmp dirs?
  • gulp.watch and gulp.src take multiple globs. some of the forEachs may not be needed
  • Why does your default task only call a temp task? Shouldn't the code in the temp task just be in the default task

@Sigmus
Copy link
Author

Sigmus commented Dec 29, 2013

@contra

  • I'm developing / serving the app at temp. Each time some html file or image gets updated it's copied
  • Will look into multiple globs, thanks!
  • It should. This script is being modified as a developed my app. There is also going to be a build task. Not sure which one will be the default, so this default task is an "alias" or a "placeholder". But you are correct.

@yocontra
Copy link

@Sigmus right now it seems like half of your code is setting up the watches. I think we can smooth that over quite a bit - I just opened gulpjs/gulp#76 about it

@Sigmus
Copy link
Author

Sigmus commented Dec 30, 2013

@contra Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment