【问题标题】:Gulp Browsersync + Babel Express server waiting for localhost indefinitelyGulp Browsersync + Babel Express 服务器无限期等待本地主机
【发布时间】:2016-09-25 02:56:14
【问题描述】:

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

当浏览器导航到网页时,我会看到一个无限加载页面,即“等待 localhost:3000”。刷新页面后网站会立即加载。

下面是我的快递服务器和 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));
}

【问题讨论】:

    标签: javascript node.js express gulp browser-sync


    【解决方案1】:

    这个问题很不幸是由babel-node引起的。

    【讨论】:

    • 如果您可以链接到错误报告/问题,那就太好了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2018-06-22
    • 2011-08-07
    相关资源
    最近更新 更多