我试图让Browsersync(版本2.12.5)与gulp-nodemon /观看文件一起使用。这些是我的一项任务。我似乎无法让我的任何文件更新/重新加载浏览器。
Submissions
将Browsersync与nodemon一起使用的推荐方法是什么?
答案 0 :(得分:1)
显然,在Browser sync
启动服务器之前,nodemon
似乎会刷新浏览器。
以下是我的命令行中显示nodemon
和Browser sync
的日志,您会看到nodemon
迟到
[18:21:09] Finished 'jade' after 5.32 μs
[18:21:09] [nodemon] restarting due to changes...
>> node restart
[BS] Reloading Browsers...
[18:21:09] [nodemon] restarting due to changes...
>> node restart
[BS] Reloading Browsers...
[18:21:09] [nodemon] restarting due to changes...
>> node restart
[BS] Reloading Browsers...
[18:21:09] [nodemon] starting `node ./bin/www`
nodemon started
我有同样的问题。以下是我的解决方案
// Initialize browserSync
var browserSync = require('browser-sync').create(),
reload = browserSync.reload;
// watcher
gulp.task('watch', function() {
var scripts = 'public/static/scripts/**/*.js';
var styles = 'public/static/styles/**/*.styl';
gulp.watch(scripts, ['scripts']);
gulp.watch(styles, ['styles']);
gulp
.watch('public')
.on('change', reload); // the static files you want to watch and reload
});
// browser-sync
gulp.task('browser-sync', function() {
browserSync.init({
proxy: 'http://localhost:3000',// Don't use proxy
port: 4000, // Desired PORT address.
open: false,
notify: false,
logConnections: false,
reloadDelay: 1000
server: 'public', // Your compiled static directory
});
})
gulp.task('default', ['scripts', 'styles', 'browser-sync', 'watch']) // This builds my script, styles and other static assets(img), starts browser-sync and watches for changes.