const path = require('path')
const webpack = require('webpack')
const config = require('./public/config/sys-config.json')
const name = config.projectName ? '^/' + config.projectName + '/myships' : '^/myships'

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

module.exports = {
  publicPath: `${config.projectName ? '/' + config.projectName : '/'}`,
  devServer: {
    proxy: {
      '/zero2/myships': {
        target: 'https://api3.myships.com/',
        changOrigin: true,
        pathRewrite: {
          [name]: ''
        }
      } ,
      '/zero2/car': {
        target: 'http://36.33.24.30:5005/',
        changOrigin: true,
        pathRewrite: {
          '/zero2/car': ''
        }
      },
      '/zeroi/free': {
        target: 'http://36.101.208.185:15380/',
        changOrigin: true,
        pathRewrite: {
          '/zeroi/free': ''
        }
      }
    }
  },
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'windows.jQuery': 'jquery'
      })
    ]
  },
  chainWebpack: (config) => {
    config.resolve.alias.set('@', resolve('./src'))
    config.resolve.extensions.add('.js').add('.vue').add('.ts').add('.json')
  }
}
