vue 配置发布测试环境,成产环境api

HeliumLau 2020-04-21

vue通过配置不同命令自动发布到测试环境或者成产环境

cnpm run build 配置开发环境

cnpm run build:test  打包到测试环境

cnpm run build:prod 打包到成产环境

vue 在vue-cli脚手架会生成build config两个文件夹

在build文件夹下新建webpack.test.conf.js 将webpack.prod.conf.js内容复制过来

将webpack.test.conf.js 修改成 const env = require(‘../config/test.env‘)

const env = require(‘../config/test.env‘)

在config新建test.env.js 将prod.env.js复制过来

test.env.js

‘use strict‘
module.exports = {
  NODE_ENV: ‘"production"‘,
  API_ROOT:‘"http://测试.com:18081/app/"‘
}

prod.env.js

‘use strict‘
module.exports = {
  NODE_ENV: ‘"production"‘,
  API_ROOT:‘"https://正式.com/app/"‘
}

dev.env.js

‘use strict‘
const merge = require(‘webpack-merge‘)
const prodEnv = require(‘./prod.env‘)

module.exports = merge(prodEnv, {
  NODE_ENV: ‘"development"‘,
  API_ROOT: ‘/api/‘
})

在build下新建test.js

将build.js内容复制到test.js

const webpackConfig = require(‘./webpack.test.conf‘)

最后修改package.json

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "e2e": "node test/e2e/runner.js",
    "test": "npm run e2e",
    "build": "node build/build.js",
    "build:test":"node build/test.js"
    
  },

相关推荐

HappinessCat / 0评论 2020-06-16