Gulp Browsersync + Babel Express 服务器无限期地等待本地主机

Gulp Browsersync + Babel Express server waiting for localhost indefinitely

我运行在一个单独的服务器文件中使用 Express 建立一个基本的静态服务器。 在我的 Gulpfile 中,我使用 nodemon 来 运行 服务器文件,然后将其地址传递给 browsersync 以代理通过。

当浏览器导航到该网页时,我看到一个无限加载的页面 "Waiting for localhost:3000"。刷新页面后网站立即加载。

下面是我的 express 服务器和 gulpfile:

// server.js

import express from 'express';
const app = express();

app.use(express.static('build'));
app.listen(4000);
// gulpfile.babel.js

import browser      from 'browser-sync';
import gulp         from 'gulp';
import plugins      from 'gulp-load-plugins';

const $ = plugins();

gulp.task('default',
  gulp.series(server, browsersync, watch));


// Start the server with nodemon
function server(done) {
  return $.nodemon({
    script: 'server.js',
    exec: 'babel-node',
  })
  .on('start', () => {
    done();
  });
}

// Proxy the server with browsersync
function browsersync(done) {
  browser.init({
    proxy: 'http://localhost:4000',
  });
  done();
}

// Watch for file changes
function watch() {
  gulp.watch('scripts/**/*.js').on('change', gulp.series(browser.reload));
}

不幸的是,此问题是由 babel-node 引起的。