express搭建文件服务器预览vue的dist文件

一分钟用express搭建文件服务器预览vue的dist文件

 

 一:hash模式

npm install express -save

//express-test.js
const express = require('express') const path = require('path') const app = express() app.use(express.static(path.join(__dirname, 'dist'))) app.listen(8081, () => { console.log('app listening on port 8081') })

执行 node express-test.js,打开浏览器输入 localhost:8081 便可以访问到项目;

 

 


 

二:history模式

使用vue-router的history模式,需要使用connect-history-api-fallback中间件

 安装 npm install --save connect-history-api-fallback

const express = require('express')
const path = require('path')
const app = express()
// vue-router history模式引入connect-history-api-fallback中间件 const history = require('connect-history-api-fallback') // 这句代码需要放在express.static上面 app.use(history()) app.use(express.static(path.join(__dirname, 'dist'))) app.listen(8081, () => { console.log('app listening on port 8081') })

 

 

 

 

 

 

posted @ 2020-12-10 20:54  Juine  阅读(373)  评论(0)    收藏  举报