vue專案打包本地部署(無後端)
阿新 • • 發佈:2021-05-17
1.拿到build後的檔案dist
2.在dist同級目錄下新建app.js檔案
3.安裝express
npm install express --save
4.app.js內容如下
var express = require('express')
var http = require('http')
var app = express()
app.use(express.static('./dist'))
app.use(function (req, res, next) {
res.sendfile('./dist/index.html') //路徑根據自己檔案配置
})
var httpsServer = http.createServer(app)
httpsServer.listen(5001, function () {
var host = httpsServer.address().address
var port = httpsServer.address().port
})
//執行app.js,即可訪問localhost://5001
node app.js