Skip to content

Instantly share code, notes, and snippets.

@dhruvr
Forked from webdesserts/Gulpfile.js
Created February 21, 2017 13:56
Show Gist options
  • Select an option

  • Save dhruvr/c08bbd82f99e531e047586da96402fc6 to your computer and use it in GitHub Desktop.

Select an option

Save dhruvr/c08bbd82f99e531e047586da96402fc6 to your computer and use it in GitHub Desktop.

Revisions

  1. @webdesserts webdesserts revised this gist Dec 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -37,5 +37,5 @@ gulp.task('default', function() {

    // clean up if an error goes unhandled.
    process.on('exit', function() {
    node.kill()
    if (node) node.kill()
    })
  2. @webdesserts webdesserts revised this gist Dec 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -37,5 +37,5 @@ gulp.task('default', function() {

    // clean up if an error goes unhandled.
    process.on('exit', function() {
    node.exit
    node.kill()
    })
  3. @webdesserts webdesserts revised this gist Dec 2, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -34,3 +34,8 @@ gulp.task('default', function() {
    // no more messing around with grunt-concurrent or the like. Gulp is
    // async by default.
    })

    // clean up if an error goes unhandled.
    process.on('exit', function() {
    node.exit
    })
  4. @webdesserts webdesserts revised this gist Dec 2, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -29,4 +29,8 @@ gulp.task('default', function() {
    gulp.watch(['./index.js', './lib/**/*.js'], function() {
    gulp.run('server')
    })

    // Need to watch for sass changes too? Just add another watch call!
    // no more messing around with grunt-concurrent or the like. Gulp is
    // async by default.
    })
  5. @webdesserts webdesserts revised this gist Dec 2, 2013. 2 changed files with 32 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    // NOTE: There are much better tools out there like nodemon that will do this for you.
    // I don't use this anymore (it had some issues), but I'm leaving it here for reference.

    var app = null

    module.exports = function(grunt) {

    grunt.initConfig({
    watch: {
    js: {
    files: ['**/*.js', '!Gruntfile.js', '!node_modules/**/*'], // add/remove where needed
    tasks: ['server'],
    options: {
    // important! Allows you to use globals
    // without it the task will be launched in it's own context
    nospawn: true
    }
    }
    },
    })

    grunt.loadNpmTasks('grunt-contrib-watch')

    grunt.registerTask('server', 'Start my server.', function() {
    if (app) app.kill();
    app = grunt.util.spawn({
    cmd: 'npm', args: ['start'], // can use "node server/index/whatever" here as well
    opts: {stdio: 'inherit'}
    });
    })

    grunt.registerTask('default', ['server','watch'])
    }
    32 changes: 32 additions & 0 deletions Gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // NOTE: I previously suggested doing this through Grunt, but had plenty of problems with
    // my set up. Grunt did some weird things with scope, and I ended up using nodemon. This
    // setup is now using Gulp. It works exactly how I expect it to and is WAY more concise.
    var gulp = require('gulp'),
    spawn = require('child_process').spawn,
    node;

    /**
    * $ gulp server
    * description: launch the server. If there's a server already running, kill it.
    */
    gulp.task('server', function() {
    if (node) node.kill()
    node = spawn('node', ['index.js'], {stdio: 'inherit'})
    node.on('close', function (code) {
    if (code === 8) {
    gulp.log('Error detected, waiting for changes...');
    }
    });
    })

    /**
    * $ gulp
    * description: start the development environment
    */
    gulp.task('default', function() {
    gulp.run('server')

    gulp.watch(['./index.js', './lib/**/*.js'], function() {
    gulp.run('server')
    })
    })
  6. @webdesserts webdesserts revised this gist Nov 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // NOTE: There are much better tools out there like nodemon to do this for you.
    // NOTE: There are much better tools out there like nodemon that will do this for you.
    // I don't use this anymore (it had some issues), but I'm leaving it here for reference.

    var app = null
  7. @webdesserts webdesserts revised this gist Nov 5, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    // NOTE: There are much better tools out there like nodemon to do this for you.
    // I don't use this anymore (it had some issues), but I'm leaving it here for reference.

    var app = null

    module.exports = function(grunt) {
  8. @webdesserts webdesserts revised this gist May 23, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,10 @@ module.exports = function(grunt) {

    grunt.registerTask('server', 'Start my server.', function() {
    if (app) app.kill();
    app = grunt.util.spawn({ cmd: 'npm', args: ['start'], opts: {stdio: 'inherit'} });
    app = grunt.util.spawn({
    cmd: 'npm', args: ['start'], // can use "node server/index/whatever" here as well
    opts: {stdio: 'inherit'}
    });
    })

    grunt.registerTask('default', ['server','watch'])
  9. @webdesserts webdesserts revised this gist May 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ module.exports = function(grunt) {

    grunt.registerTask('server', 'Start my server.', function() {
    if (app) app.kill();
    app = grunt.util.spawn({ cmd: 'npm', args: ['start'] });
    app = grunt.util.spawn({ cmd: 'npm', args: ['start'], opts: {stdio: 'inherit'} });
    })

    grunt.registerTask('default', ['server','watch'])
  10. @webdesserts webdesserts revised this gist May 23, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,11 @@

    var app = null

    module.exports = function(grunt) {

    grunt.initConfig({
    watch: {
    js: {
    files: ['**/*.js', '!Gruntfile.js', '!node_modules/**/*'],
    files: ['**/*.js', '!Gruntfile.js', '!node_modules/**/*'], // add/remove where needed
    tasks: ['server'],
    options: {
    // important! Allows you to use globals
  11. @webdesserts webdesserts created this gist May 23, 2013.
    28 changes: 28 additions & 0 deletions Gruntfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@

    var app = null

    module.exports = function(grunt) {

    grunt.initConfig({
    watch: {
    js: {
    files: ['**/*.js', '!Gruntfile.js', '!node_modules/**/*'],
    tasks: ['server'],
    options: {
    // important! Allows you to use globals
    // without it the task will be launched in it's own context
    nospawn: true
    }
    }
    },
    })

    grunt.loadNpmTasks('grunt-contrib-watch')

    grunt.registerTask('server', 'Start my server.', function() {
    if (app) app.kill();
    app = grunt.util.spawn({ cmd: 'npm', args: ['start'] });
    })

    grunt.registerTask('default', ['server','watch'])
    }