新建的vue项目,默认是没有vue.config.js文件,在根目录下自建该目录然后配置以下代码:
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '/nakAppServer/ncpReport/' : '/',
outputDir: "ncpReport", // 在npm run build时 生成文件的目录 default:'dist',此处定义为 ncpReport
assetsDir: "static", // 放置生成的静态资源 (js、css、img、fonts) 的目录。default: ''
indexPath: "index.html",
lintOnSave: false,//是否需要在保存时执行lint格式化校验
runtimeCompiler: true,
productionSourceMap: false,//如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
pages: {
// 多页配置(单页应用只需要配置入口页面,注意路径)
index: {
entry: "src/index.js", // 配置入口js文件
template: "public/index.html", // 主页面
filename: "index.html", // 打包后的html文件名称
title: "首页", // 打包后的.html中<title>标签的文本内容
// 在这个页面中包含的块,默认情况下会包含
// 提取出来的通用 chunk 和 vendor chunk。
chunks: ['chunk-vendors', 'chunk-common', 'index']
}
},
devServer: {
// host:'接口的访问域名(后台提供给前端)',
proxy: {
'/api': {
target: '接口访问的域名(后台提供给前端,同以上)', // 设置你调用的接口域名
changeOrigin: true, // 是否跨域
ws: true,
pathRewrite: {
'^/api': '/' // 这里可以理解为用‘/api’来代替target里面的地址
}
}
}
},
注意:在封装的axios类中,需要注意
axios.defaults.baseURL ="/api";
当发布正式包时,将此配置为后台域名,如:
axios.defaults.baseURL ="http://test.xxxxxx.com/“;
说明:该配置在vue-cli3创建的项目中可以正常使用。