Open heinhoang opened 7 years ago
@heinhoang Did you ever figure out the problem? I'm having the same issue.
hey @amack459, yes, I figured out why it is:
I use mongoose connect mongoose.connect(url)
and it works asynchronously.
After gulp-nodemon finished it's tasks but mongoDb has not finished the connection yet so browsersync waiting for locallhost and it's loading and loading.
Then, after MongoDb connection finished but browsersync doesn't know about that and it continues loading.
Solution 1 is that: You can setTimeout() to wait for a few seconds before starting browser-sync task. Solution 2: may be better // Step 1: Write a logging file to inform connection finished
mongoose.connection
.once('open', () => {
fs.writeFile(`${app.get('rootDir')}/dbConnection.log`, `database connected on ${new Date()}`, (err) => {
if (err) throw err;
});
})
// Step 2: watch the log file and start browser-sync
gulp.task('log:watch', (cb) => {
gulp.watch('./dbConnection.log', () => {
let called = false;
if (!called) {
cb();
called = true;
gulp.start('browser-sync');
}
});
});
"gulp-nodemon": "^2.2.1" "browser-sync": "^2.18.12" "gulp": "^3.9.1
gulpfile.js
It's loading too slow before render a page. Here's the output on console: