VUE多项目配置,网上找的解决方案

VUE项目配置

示例:有两个项目

第一个:打包到 `test1`目录中;

第二个:打包到 `test2` 目录中;

注意:第二个项目需要需要做以下修改,然后再进行打包。第一个项目啥都不用动,就用默认的配置就行。

1、vue.config.js 中,添加:publicPath: '/test2' 配置项

2、router.js 中,添加: base: '/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;
    }
}
(仅供参考)

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值