Last active
May 1, 2016 00:19
-
-
Save gregorskii/413b0388978146899dc83983ce765238 to your computer and use it in GitHub Desktop.
nodemon as a gulp task
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
'use strict'; | |
import {gulp, plugins, config} from '../plugins'; | |
import proxyMiddleware from 'http-proxy-middleware'; | |
const proxy = 'localhost:8002'; | |
/** | |
* Watch Task: gulp watch | |
*/ | |
gulp.task('watch', plugins.sequence('nodemon', 'bundle', 'browserSync', 'watch-start')); | |
gulp.task('browserSync', (done) => { | |
config.browserSyncConfig = { | |
proxy: { | |
target: proxy, | |
middleware: [proxyMiddleware(['api'], {target: `http://${proxy}/api`})] | |
} | |
}; | |
plugins.browserSync.init(config.browserSyncConfig, (err) => { | |
if (!err) { | |
done(); | |
} else { | |
throw new Error('Error starting BrowserSync'); | |
} | |
}); | |
}); | |
gulp.task('watch-start', (done) => { | |
plugins.util.log(plugins.util.colors.cyan('Watching for changes...')); | |
plugins.watch([ | |
config.src + '/scripts/**/*' + config.extensionGlobs.js, | |
config.src + '/scripts/**/*' + config.extensionGlobs.vue, | |
'!' + config.src + '/scripts/**/' + '**_scsslint_tmp**.js' | |
], () => { | |
return gulp.start('webpack'); | |
}); | |
plugins.watch(config.src + '/views/' + config.extensionGlobs.views, () => { | |
return gulp.start('views'); | |
}); | |
plugins.watch(config.src + '/fonts/' + config.extensionGlobs.fonts, () => { | |
return gulp.start('fonts'); | |
}); | |
plugins.watch(config.src + '/images/' + config.extensionGlobs.images, () => { | |
return gulp.start('images'); | |
}); | |
plugins.watch(config.src + '/styles/' + config.extensionGlobs.sass, () => { | |
return gulp.start('sass'); | |
}); | |
done(); | |
}); |
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
'use strict'; | |
import {gulp, plugins} from '../plugins'; | |
import nodemon from 'nodemon'; | |
gulp.task('nodemon', (done) => { | |
let initial = true; | |
return nodemon({ | |
script: './server/index.js', | |
ignore: [ | |
'gulp/**', | |
'node_modules/**', | |
'bower_components/**', | |
'server/app/public/**' | |
] | |
}).on('start', () => { | |
if (initial) { | |
done(); | |
initial = false; | |
} | |
}).on('restart', (files) => { | |
setTimeout(() => { | |
plugins.browserSync.reload({ | |
stream: false | |
}); | |
}, 1000); | |
plugins.util.log(plugins.util.colors.cyan('Express app restarted due to: ', files)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Must be used in a sequence where regular gulp tasks run, this task is allowed to run en full before changing directories back.
Assumes server is located in
./server
and is started byindex.js
.