我正在尝试使用 grunt-http-server
https://www.npmjs.com/package/grunt-http-server
我按照链接上的示例进行操作
'http-server': {
'dev': {
// the server root directory
root: apps,
// the server port
// can also be written as a function, e.g.
// port: function() { return 8282; }
port: 8282,
// the host ip address
// If specified to, for example, "127.0.0.1" the server will
// only be available on that ip.
// Specify "0.0.0.0" to be available everywhere
host: "127.0.0.1",
cache: 10,
showDir : true,
autoIndex: true,
// server default file extension
ext: "html",
// run in parallel with other tasks
runInBackground: true,
// specify a logger function. By default the requests are
// sent to stdout.
logFn: function(req, res, error) { }
}
},
当我运行任务时
grunt http-server:dev
任务正在运行但停止了
Running "http-server:dev" (http-server) task
Server running on 127.0.0.1:8282
Hit CTRL-C to stop the server
Done, without errors.
当我访问 127.0.0.1:8282 时,我发现页面不可用。 我必须做什么才能使任务继续运行并提供我的文件。
最佳答案
您需要设置runInBackground: false
。
因为runInBackground
告诉grunt:
- when
true
:继续运行其余任务。 - when
false
:停止并无限期地等待服务器。
在您的情况下,当设置为 true
时,没有其他任务可以运行,因此 grunt 终止并删除它启动的所有内容,包括您的服务器。例如,如果您通过 watch
任务跟随服务器启动,true
将会很有用。
关于gruntjs - grunt-http-server 停止运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682896/