vue-cli-service serve
用法:vue-cli-service serve [options] [entry]选项:
–open 在服务器启动时打开浏览器
–copy 在服务器启动时将 URL 复制到剪切版
–mode 指定环境模式 (默认值:development)
–host 指定 host (默认值:0.0.0.0)
–port 指定 port (默认值:8080)
–https 使用 https (默认值:false)
vue-cli-service build
用法:vue-cli-service build [options] [entry|pattern]选项:
–mode 指定环境模式 (默认值:production)
–dest 指定输出目录 (默认值:dist)
–modern 面向现代浏览器带自动回退地构建应用
–target app | lib | wc | wc-async (默认值:app)
–name 库或 Web Components 模式下的名字 (默认值:package.json 中的 “name” 字段或入口文件名)
–no-clean 在构建项目之前不清除目标目录
–report 生成 report.html 以帮助分析包内容
–report-json 生成 report.json 以帮助分析包内容
–watch 监听文件变化
以上是两个常用的cli指令 , 他们默认对应的分别是development和production模式 , 如果还想了解其他指令 , 可以访问: https://cli.vuejs.org/zh/guide/cli-service.html#cli-%E6%9C%8D%E5%8A%A1 CLI 服务
那么接下来 , 我们就开始创建一个用于打包测试环境的模式;
修改package.json
添加一行命令
"test": "vue-cli-service build --mode test"添加.env.test文件
在项目根路径创建.env.test文件,内容为
NODE_ENV='production' //表明这是生产环境(需要打包)
VUE_APP_CURRENTMODE='test' // 表明生产环境模式信息
VUE_APP_BASEURL='http://***.****.com:8000' // 测试服务器地址修改项目中的api接口文件
在我的项目中,一般会创建一个api.js 来管理所有的接口url
因为我们在本地开发环境中是通过代理来连接服务器的,所以将url写成这
`${baseUrl}/apis/v1/login`,在文件开头通过环境变量改变baseUrl
let baseUrl = '';
if (process.env.NODE_ENV == 'development') {
baseUrl = ""
} else if (process.env.NODE_ENV == 'production') {
baseUrl = process.env.VUE_APP_BASEURL
} else {
baseUrl = ""
}当需要为测试环境进行打包的时候 , 我们只需要运行下面指令进行打包
npm run test










