vue-cli中配置开发环境、测试环境和生成环境

127 阅读1分钟

首先在script中配置

"scripts": {
    "serve": "vue-cli-service serve ",
    "dist": "release=false vue-cli-service build --mode test",
    "release": "release=true vue-cli-service build"
  },

在vue.config.js配置如下

const $path = require('./configs/webpack.params')
const distConfig = {
  publicPath: $path.cdn_path_dist,
}
const releaseConfig = {
  publicPath: $path.cdn_path_release,
  outputDir:'release',
  productionSourceMap:false
}
if(process.env.release) {
  module.exports = process.env.release === 'true' ? releaseConfig:distConfig
} else {
  module.exports = {
    devServer: {
      port: '3008',
      host: '0.0.0.0',
      disableHostCheck: true,
    }
  }
}

webpack.params.js中设置如下

module.exports = {
    "cdn_path_dist" : "",
    "cdn_path_release" : ""
}