GithubHelp home page GithubHelp logo

isterin / gulp-nodemon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jacksongariety/gulp-nodemon

0.0 1.0 0.0 127 KB

it's gulp + nodemon + convenience

JavaScript 99.49% CoffeeScript 0.51%

gulp-nodemon's Introduction

gulp-nodemon

it's gulp + nodemon + convenience

Install

$ npm install --save-dev gulp-nodemon

Usage

Gulp-nodemon looks almost exactly like regular nodemon, but it's made for use with gulp tasks.

nodemon([options])

You can pass an object to gulp-nodemon with options like you would in nodemon config.

Example below will start server.js in development mode and watch for changes, as well as watch all .html and .js files in the directory.

gulp.task('start', function () {
  nodemon({
    script: 'server.js'
  , ext: 'js html'
  , env: { 'NODE_ENV': 'development' }
  })
})

Synchronous Build Tasks

NOTE: This feature requires Node v0.12 because of child_process.spawnSync.

Nodemon is powerful but lacks the ability to compile/cleanup code prior to restarting the application... until now! Most build systems can never be complete without compilation, and now it works harmoniously with your nodemon loop.

{ tasks: [Array || Function(changedFiles)] }

If you want to lint your code when you make changes that's easy to do with a simple event. But what if you need to wait while your project re-builds before you start it up again? This isn't possible with vanilla nodemon, and can be tedious to implement yourself, but it's easy with gulp-nodemon:

nodemon({
  script: 'index.js'
, tasks: ['browserify']
})

What if you want to decouple your build processes by language? Or even by file? Easy, just set the tasks option to a function. Gulp-nodemon will pass you the list of changed files and it'll let you return a list of tasks you want run.

nodemon({
  script: './index.js'
, ext: 'js css'
, tasks: function (changedFiles) {
    var tasks = []
    changedFiles.forEach(function (file) {
      if (path.extname(file) === '.js' && !~tasks.indexOf('lint')) tasks.push('lint')
      if (path.extname(file) === '.css' && !~tasks.indexOf('cssmin')) tasks.push('cssmin')
    })
    return tasks
  }
})

Events

gulp-nodemon returns a stream just like any other NodeJS stream, except for the on method, which conveniently accepts gulp task names in addition to the typical function.

.on([event], [Array || Function])

  1. [event] is an event name as a string. See nodemon events.
  2. [tasks] An array of gulp task names or a function to execute.

Example

The following example will run your code with nodemon, lint it when you make changes, and log a message when nodemon runs it again.

// Gulpfile.js
var gulp = require('gulp')
  , nodemon = require('gulp-nodemon')
  , jshint = require('gulp-jshint')

gulp.task('lint', function () {
  gulp.src('./**/*.js')
    .pipe(jshint())
})

gulp.task('develop', function () {
  nodemon({ script: 'server.js'
          , ext: 'html js'
          , ignore: ['ignored.js']
          , tasks: ['lint'] })
    .on('restart', function () {
      console.log('restarted!')
    })
})

gulp-nodemon's People

Contributors

happytobi avatar acousineau avatar davelnewton avatar dimitardanailov avatar gaborluk avatar morenoh149 avatar isterin avatar binarykitchen avatar raine avatar ryanwild avatar tschaub avatar sonicoder86 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.