我将grunt-contrib-watch和grunt-contrib-connect设置为live,如下所示:
watch: {
options: {
livereload: true,
},
files: ['src/**/*'],
tasks: ['serve']
},
connect: {
server: {
options: {
port: 8000,
base: './dist',
hostname: '0.0.0.0',
protocol: 'http',
livereload: true,
open: true,
}
}
},但是,当connect试图重新加载时,我得到了这个错误:
运行"connect:server“(connect:server)任务致命错误:端口8000已被其他进程使用。
我尝试了几个不同的端口,但也遇到了同样的问题。
我不明白grunt-contrib-connect服务器如何与它自己的端口发生冲突。
我怎么才能让这个起作用?
发布于 2018-07-31 21:14:47
原来,serve任务是我启动服务器的地方,所以每次重新加载时,它都试图启动另一台服务器。我把它切换到一个dev任务,在那里站点被重新编译,但是没有启动服务器。
发布于 2018-07-31 21:08:20
以下几项要求:
确保您还没有在其他地方启动localhost 8000。如果两个本地服务器运行在同一个端口上,它将无法工作。(检查终端中的其他选项卡)
确保以下内容在您的html中(与其他js一起位于底部)
<script src="//localhost:35729/livereload.js"></script>然后尝试这样的方法:
connect: {
server: {
options: {
port: 8000,
hostname: 'localhost',
livereload: 35729,
open:{
target: "http://localhost:8000"
}
}
}
},
watch: {
options: {
livereload: true,
},
css: {
files: ['src/**/*'],
options: {
spawn: false,
},
},
html: {
files: ["**/*.html"]
}
},如果您不喜欢,则可以设置一个任务:
grunt.registerTask("server", ["connect", "watch"]); // Type grunt server -- Creates a server and checks for any changes in the html/css发布于 2020-04-24 23:38:58
可能是另一种情况,但无论我在gruntfile文件中设置了哪个端口号,我都会收到完全相同的错误消息。事实证明,问题是由于我将端口号定义为字符串,而不是数字。
https://stackoverflow.com/questions/51619516
复制相似问题