尝试使用 yeoman 在虚拟机上设置 Angular,以避免包管理破坏我的机器。
使用 yo myproject
生成项目后,全局和本地安装 Angular,使用 Bower 和更多依赖项安装 grunt,我可以使用 gruntserve
运行服务器
可以通过 wget localhost
从虚拟机访问 localhost
,但它不会从主机加载。
我尝试将文件 /etc/network/interface
修改为 static address并从浏览器访问静态IP,也可以访问set dynamic DHCP带端口转发
没有任何效果,浏览器无法建立连接:
Firefox can't establish a connection to the server at
我想上传更多有用的文件/输出以提供更多上下文,但作为一个新的 grunt 用户,我不知道该去哪里查看。
最佳答案
设置 connect-middleaware 监听 0.0.0.0 IP 地址以确保主机可访问。
您可以像这样编辑 Gruntfile.js。
在grunt.initConfig({})中找到
将connect
任务;options
中的主机名更改为0.0.0.0
它应该看起来像这样:
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.',
'examples'
]
}
}
},
运行gruntserve
,尝试使用vm ip从主机访问ip。它应该可用。
关于networking - 如何从主机请求 grunt 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24443825/