快速搭建可以运行的服务器环境
1. 安装express
npm install express -g
- 如果打包的文件是普通的项目,
路由
设计采用的是hash
,那么就只需要用static
这个中间件就可以处理
大部分静态资源
请求了 - 如果是vue项目且路由采用history,那么就需要下载一个处理history资源请求的中间件了(
connect-history-api-fallback
)
2. 安装connect-history-api-fallback中间件
npm install connect-history-api-fallback
3. 服务端启动
const express = require("express")
const history = require("connect-history-api-fallback")
const app = express()
app.use(history())
app.use(express.static(__dirname+"/dist"))
const port = 3000
app.listen(port,()=>{
console.log("服务端已启动")
})
node app