第一种:当 axios.js 是如下配置时,则按照下面方法:
在这里插入图片描述
下方是我微信公众号的二维码,可以扫码关注以下,后期博文推送主要在公众号上面,有什么问题也可以通过公众号跟我发消息哦~
在这里插入图片描述

1、在 build —> webpack.base.conf.js

let publicPath = ''
if (process.env.NODE_ENV === "production") {
  publicPath = config.build.assetsPublicPath
} else if (process.env.NODE_ENV === "testing") {
  publicPath = '/xxx' + config.dev.assetsPublicPath   //  xxx 为二级目录名
}
//或者下面的
//let publicPath = ''
//if(process.env.NODE_ENV === 'production'){
//  publicPath= '/xxx' + config.build.assetsPublicPath
//}else if(process.env.NODE_ENV === 'testing'){
//  publicPath = '/xxx' + config.dev.assetsPublicPath
//}else{
//  publicPath = config.dev.assetsPublicPath
//}


module.exports = {
   ...
    output: {
        path: config.build.assetsRoot,
        filename: '[name].js',
        publicPath
    },
    ...
}

在这里插入图片描述
如果在 axios.js 中配置的了正式的地址和测试的地址,如下图,
则:打包之后正式的地址为 http://www.xxx.com:8089/xxx/#/
打包之后测试的地址为 http://192.168.xxx.xxx:8000/xxx/#/在这里插入图片描述

注: 如果打包之后,资源找不到,则:在: build —> utils.js

 if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader',
        publicPath:'../../'    // 设置打包过程中提取css的方法 ,解决背景图片路径的问题。
      })
    } else {
      return ['vue-style-loader'].concat(loaders)
    }

在这里插入图片描述
第二种:
当 axios.js 是如下配置时,则按照下面方法:
在这里插入图片描述

1、在 build —> webpack.base.conf.js

let publicPath = ''
if (process.env.NODE_ENV === "production") {
  publicPath = '/xxx + config.build.assetsPublicPath    //  xxx 为二级目录名
} else if (process.env.NODE_ENV === "testing") {
  publicPath = '/xxx' + config.dev.assetsPublicPath
}
module.exports = {
  context: path.resolve(__dirname, '../'),
  entry: {
    app: './src/main.js'
  },
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath,
  },
  ...
}

在这里插入图片描述
2、在 config —> dev.env.js 里
在这里插入图片描述
3、在 config —> prod.env.js 里
在这里插入图片描述
4、在 config —>test.env.js 里
在这里插入图片描述

Logo

前往低代码交流专区

更多推荐