背景:公司要求将之前用不同端口号区分的三个独立的系统统一配置到统一域名下。
VUE项目配置
示例:有两个项目
第一个:打包到 `test1`目录中;
第二个:打包到 `test2` 目录中;
// vue.config.js
module.exports = {
lintOnSave: false,
productionSourceMap: false,
publicPath: '/test2',
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
return {
};
} else {
}
}
};
// src/router.js
import Vue from 'vue';
import Router from 'vue-router';
import routes from './routes.js';
Vue.use(Router);
const router = new Router({
base: '/test2',
mode: 'history',
routes
});
export default router;
对第二个项目打包,打完了以后,看一下 dist 目录中的 index.html文件,会发现引入文件时,给加上了 /test2/ 这个前缀,这个到时候要与Nginx的location配置相对应。
Nginx 配置
server {
listen 80;
server_name www.badudu.cn;
# 项目二的配置
location /management/ {
alias /home/mall/test2/; # 这里注意要用 `alias`
index index.html index.htm;
try_files $uri $uri/ /test2/index.html;
}
# 项目一的配置
location / {
root /home/mall/test1/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
(仅供参考)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)