winserver发布nodejs express+vuejs项目

1、build前端项目

发布时不需要.map文件,创建vue.config.js文件添加如下内容

module.exports = {
    productionSourceMap: false,
};

2、服务端映射静态资源

app.use(express.static(path.join(__dirname, 'public')));

3、前端router采用history模式,发布后刷新页面或者打开新窗口时会发起网络请求而不是使用前端的router而导致404错误

解决办法:按 官方的推荐 使用中间件 connect-history-api-fallback

const history = require('connect-history-api-fallback');

app.use(history());

4、为了方便管理,使用 node-windows 注册服务,管理我们的应用程序

新建文件 install.js,输入内容

const Service = require('node-windows').Service;

const svc = new Service({
    name: 'xxx',  // 服务名称
    description: 'xxx',  // 描述
    script: 'xxx\index.js',  // nodejs项目要启动的文件路径
});

svc.on('install', () => {
    svc.start();
});

svc.install();

5、将nodejs项目拷贝到服务器,安装模块

6、将vuejs项目build生成的所有文件拷贝到服务器的public目录下

7、在项目根目录打开控制台,注册服务

node install.js

8、打开控制面板->服务,找到上面注册的服务,启动

完成!!!

原文地址:https://www.cnblogs.com/laoq112/p/14069664.html