一步步创建vue-element-admin框架实现003-添加配置文件

一步步创建vue-element-admin框架实现003-添加配置文件

使用说明:

一步步创建vue-element-admin框架是基于vue-element-admin和vue-admin-template基础版的代码来实现的,文章会经常说直接拷贝项目的文件

配置文件:vue.config.js,cli3的配置文件

const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: '/',
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false,
  devServer: {
    port: 9210
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  }
}

配置文件:jsconfig.json,对所有js代码做出个性化支持

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
        "@/*": ["src/*"]
    }
  },
  "exclude": ["node_modules", "dist"]
}

添加配置文件之后,现在可以@来代替src路径使用,比如路由配置的

export const constantRoutes = [
  {
    path: '/helloWord',
    component: () => import('@/components/HelloWord'),
    hidden: true
  },
  {
    path: '/test',
    component: () => import('../components/Test'),
    hidden: true
  }
]

配置文件:.env.development或.env.production,全局环境变量配置文件

.env.development

# just a flag
ENV = 'development'

# base api
VUE_APP_BASE_API = '/dev-api'

# port
PORT = 9101

.env.production

# just a flag
ENV = 'production'

# base api
VUE_APP_BASE_API = '/prod-api'

# port
PORT = 9201

使用配置内容:process.env.xxx(process.env.PORT)

设置端口,在vue.config.js里

module.exports = {
  devServer: {
    port: process.env.PORT || 8080
  },
}

在request.js设置

// 创建axios实例
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // 请求超时设置
})

使用那个配置文件信息,在package.json启动命令设置:–mode development

"scripts": {
  "serve:dev": "vue-cli-service serve --mode development",
  "serve:prod": "vue-cli-service serve --mode production",
  "build": "vue-cli-service build",
  "lint": "vue-cli-service lint"
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

binggoling

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值