在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JacksonGariety/gulp-nodemon开源软件地址(OpenSource Url):https://github.com/JacksonGariety/gulp-nodemon开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-nodemongulp + nodemon + convenience Install$ npm install --save-dev gulp-nodemon UsageGulp-nodemon is almost exactly like regular nodemon, but it's made for use with gulp tasks. nodemon([options])Gulp-nodemon takes an options object just like the original. Example below will start gulp.task('start', function (done) {
nodemon({
script: 'server.js'
, ext: 'js html'
, env: { 'NODE_ENV': 'development' }
, done: done
})
}) Synchronous Build TasksNOTE: This feature requires Node v0.12 because of Gulp-nodemon can synchronously perform build tasks on restart. { 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 NOTE: If you manually restart the server ( nodemon({
script: './index.js'
, ext: 'js css'
, tasks: function (changedFiles) {
var tasks = []
if (!changedFiles) return 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
}
}) Eventsgulp-nodemon returns a stream just like any other NodeJS stream, except for the .on([event], [Array || Function])
.emit([event])
ExamplesBasic UsageThe 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 (done) {
var stream = nodemon({ script: 'server.js'
, ext: 'html js'
, ignore: ['ignored.js']
, tasks: ['lint'] })
, done: done
stream
.on('restart', function () {
console.log('restarted!')
})
.on('crash', function() {
console.error('Application has crashed!\n')
stream.emit('restart', 10) // restart the server in 10 seconds
})
}) You can also plug an external version or fork of nodemon gulp.task('pluggable', function() {
nodemon({ nodemon: require('nodemon'),
script: 'server.js'})
}) Bunyan Logger integrationThe bunyan logger includes a gulp.task('run', ['default', 'watch'], function(done) {
var nodemon = require('gulp-nodemon'),
spawn = require('child_process').spawn,
bunyan
nodemon({
script: paths.server,
ext: 'js json',
ignore: [
'var/',
'node_modules/'
],
watch: [paths.etc, paths.src],
stdout: false,
readable: false,
done: done
})
.on('readable', function() {
// free memory
bunyan && bunyan.kill()
bunyan = spawn('./node_modules/bunyan/bin/bunyan', [
'--output', 'short',
'--color'
])
bunyan.stdout.pipe(process.stdout)
bunyan.stderr.pipe(process.stderr)
this.stdout.pipe(bunyan.stdin)
this.stderr.pipe(bunyan.stdin)
});
})
Using |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论