[英]Creating an NPM START script in package.json
So I'm trying to create a script that when someone makes npm start it starts a localhost. 因此,我正在尝试创建一个脚本,当有人启动npm时,它将启动一个本地主机。 Now this is what I have on my package.json :
现在这就是我的package.json上的内容 :
"scripts": {
"start": "npm run open",
"open": "concurrently \"http-server -a localhost -p 1234\" \"sleepms 1000 && open http://localhost:1234/public/index.htm\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"concurrently": "^3.5.1",
"http-server": "^0.10.0",
"opn-cli": "^3.1.0",
"sleep-ms": "^2.0.1"
}
But what I'm getting is a 404 of the localhost... 但是我得到的是本地主机的404 ...
Thank you 谢谢
您应该在项目的根目录中有一个public
目录,其中包含一个index.html文件。
Per the http-server
documentation ... 根据
http-server
文档 ...
http-server [path] [options]
[path] defaults to ./public if the folder exists, and ./ otherwise.
如果文件夹存在,则[path]默认为./public,否则为./。
Since you are not passing a path, it's defaulting to ./public as its root directory, so you do not need to include /public
in your URL. 由于您未传递路径,因此默认将./public作为其根目录,因此您无需在URL中包括
/public
。
Try accessing http://localhost:1234/index.htm instead of http://localhost:1234/public/index.htm 尝试访问http:// localhost:1234 / index.htm而不是http:// localhost:1234 / public / index.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.