全局安装npm install serve -g
这个时候我们就可以,将server封装成scripts
通过 npm scripts,将启动服务命令封装成 npm run start
{
"name": "deploy-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "serve . -p 3000"
},
"author": "",
"license": "ISC"
}
创建一个index.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
xiumubai
</body>
</html>
运行npm run start
,即可启动3000端口的一个服务。
在浏览器地址打开http://localhost:3000
,即可看到下面的页面