http-server如何在本地测试react/vue项目
http-server是一个简单的零配置命令行http服务器。它对于生产使用来说是足够强大的,但它的测试,本地开发和学习足够简单易用
·
1.简介
http-server是一个简单的零配置命令行http服务器。它对于生产使用来说是足够强大的,但它的测试,本地开发和学习足够简单易用
2.安装
1.全局安装:
npm install -g http-server
1-2.mac下全局安装
brew install http-server
3.使用方法
http-server [path] [options]
[path] defaults to ./public if the folder exists, and ./ otherwise.
http-server启动后默认是在当前./public的文件夹,否则的话./。
端口号:默认为8080
如果与你其他开启的服务有冲突,可以通过
-p 要使用的端口来修改端口号
现在,可以访问http://localhost:8080来查看您的服务器
http-server -c -1 禁用缓存
4.在react || vue项目下启动服务
首先执行npm run build 打包命令在跟目录下生成新的build目录或者dist目录【以webpack中配置】
1. 执行npm run build
2. cd dist
3. http-server
5.结果
输出以下内容则表示成功,将IP复制到你手机的浏览器中就可以在手机上访问你的项目了嘎嘎
Starting up http-server, serving ./ through https
Available on:
https:127.0.0.1:8080
https:192.168.1.101:8080
https:192.168.1.104:8080
Hit CTRL-C to stop the server
更多推荐
所有评论(0)