vue.config.js 基础配置

1. 项目打包之后默认放在dist文件中,可以通过outputDir,assetsDir,indexPath改变默认打包位置。

module.exports = {
     outpurDir: './Web',   // 文件打包生成环境构建文件目录,默认为dist目录
     assetsDir: 'vue-admin',  // 放置静态资源,js css img fonts
     indexpath: 'View/index.cshtml', //  生成的index.html的输出路径
}

 

 但是每次打包的时候web都先回被清除,因为我们前端打包的只是前端的代码,如果该目录下存在其他代码,就也会把他们清除,这样很容易造成问题。

暂时解决办法:在package.json文件中build后面加上 --no-clean

 

 2. devServer.proxy代理

    若前端和后端的api服务器没有运行在一个主机上,需要在开发环境下将api请求代理到api服务器上。

    devServer: {
        port: 8092, // 端口号,如果端口号被占用,会自动加1
        open: true, // 启动服务时是否自动打开浏览器访问
        proxy: { // 代理
            '/mobile': { // ‘/mobile’数据请求下匹配的接口前缀
                // target目标还可直接写例如.env.production NODE_ENV=production: VUE_APP_URL=http://gjxqa.uatwechat.com,
                // target: process.env.VUE_APP_URL
                target: 'http://。。。.com', // 目标
                changeOrigin: true, // 解决跨域问题
                ws: true
            }
        }
    }

在默认环境下,不接受运行在https上,且使用了无效证书的后端服务器,如果想要接受,只要设置secure:false就行。

posted @ 2021-10-19 10:20  小黄花呐  阅读(238)  评论(0编辑  收藏  举报