我正在尝试使用gulp和browser-sync在Windows 10计算机上设置开发环境,但我无法让服务器做出响应。
访问localhost:5000会在Chrome上显示“ERR_CONNECTION_CLOSED”。我能够以127.0.0.1:5000来解决这个问题,但现在我已经被浏览器永远加载了。
这是我的gulpfile:
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
});
app.listen(5000);
我的app.js,启动服务器:
var gulp = require('gulp');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
gulp.task('default', ['browser-sync'], function () {
});
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init(null, {
proxy: "http://localhost:5000",
files: ["public/**/*.*"],
browser: "google chrome",
port: 7000,
});
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: 'app.js'
}).on('start', function () {
// to avoid nodemon being started multiple times
// thanks @matthisk
if (!started) {
cb();
started = true;
}
});
});
的package.json:
{
"name": "tst",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"browser-sync": "^2.18.13",
"express": "^4.16.2",
"gulp": "^3.9.1",
"gulp-nodemon": "^2.2.1",
"pug": "^2.0.0-rc.4"
}
}
作为参考,我正在使用此仓库中的代码:https://gist.github.com/sogko/b53d33d4f3b40d3b4b2e
无论如何我可以在Windows 10上使用它吗?