有时候在本地开发,你的本地资源可能会遇到安全性问题而无法进行加载,你得需要http协议,you need a local web server,在mac下,http-server可以快速帮你解决这个问题。

全局安装http-server

1
npm install http-server -g

启动本地服务器

1
http-server [path] [options]

例如,http server .代表在当前目录启动服务,当前目录为根目录,127.0.0.1:8080指向当前目录,如果有index.html或者index.php,指向该页面;http server ./website 在当前目录下的website目录启动服务,./website为根目录,127.0.0.1:8080指向./website,如果有index.html或者index.php,指向该页面;默认端口8080可变,另外,你还可以带上某些参数,详情请看http-server