安装Node.js和vue-cli
参考https://mp.csdn.net/mp_blog/creation/editor/142427043
生成Vue demo和编译Vue来生成静态文件(包括index.html,js文件等等)
参考https://mp.csdn.net/mp_blog/creation/editor/142427043
生成一个nodejs server 目录并初始化
mkdir node-server
cd node-server
npm init
安装依赖
npm install express
编写node-server.js
javascript
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, '../web/dist')));
app.get('/', (req, res) => {
res.send(path.join(__dirname, '../web/dist/', 'index.html'));
})
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
})
启动node server
node .\node-server.js