const autoprefixer = require('autoprefixer')
const pxtoviewport = require('postcss-px-to-viewport')
const path = require('path')
const port = process.env.port || process.env.npm_config_port || 9528 // dev port
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  outputDir: ' dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV === 'development',
  publicPath: '/',
  css: {
    loaderOptions: {
      less: {
        // 若使用 less-loader@5，请移除 lessOptions 这一级，直接配置选项。
        modifyVars: {
          // 直接覆盖变量
          'blue': '#F25D24'
        }
      },
      postcss: {
        plugins: [
          autoprefixer(),
          pxtoviewport({
            viewportWidth: 375
          })
        ]
      }
    }
  },
  chainWebpack: (config) => {
    config.entry('main').add('babel-polyfill')
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
  devServer: {
    port: port,
    open: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      // change xxx-api/login => mock/login
      // detail.vue: https://cli.vuejs.org/config/#devserver-proxy
      [process.env.VUE_APP_BASE_API]: {
        // target: `http://58.56.15.138:20189/`,
        target: `http://api.dms.66km.com.cn/`,
        timeout: 8640000,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    }
  }
}
