vue configure publishing test environment to a production environment api

vue automatically published by different commands to configure the test environment to the production environment, or

cnpm run build configuration development environment

cnpm run build: test package to the test environment

cnpm run build: prod packaged into the production environment

vue vue-cli in scaffolding will generate two build config folder

In the build folder under the new webpack.test.conf.js copied content will webpack.prod.conf.js

The modified webpack.test.conf.js const env = require ( '../ config / test.env')

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

In the new config will prod.env.js copied test.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/'
})

New test.js in the build

Copy the contents to test.js build.js

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

Last Modified 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"
    
  },

 

Guess you like

Origin www.cnblogs.com/junwu/p/11243116.html