const path = require('path')
const isProdMode = Object.is(process.env.NODE_ENV, 'production')
const baseUrl = process.env.BASE_URL || (isProdMode ? 'http://10.10.100.107:8081/platform-b2c/' : 'http://192.168.253.60:9090/platform-b2c/')

module.exports = {
  router: {
    middleware: 'check-auth'
  },
  /*
  ** Headers of the page
  */
  head: {
    title: '【优软商城】IC电子元器件现货采购交易平台商城',
    meta: [
      { charset: 'utf-8' },
      { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
      { name: 'render', content: 'webkit' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '优软商城（usoftmall.com）是中国领先的IC电子元器件现货采购交易网上商城，提供上千万种电子元器件现货采购交易，采购电子元器件就上优软商城！' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#3B8070' },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** Run ESLINT on save
    */
    extend (config, { dev, isClient, isServer }) {
      config.resolve.alias['~utils'] = path.join(__dirname, 'utils')
      config.module.rules.push({
        test: /\.scss$/,
        loader: 'vue-style-loader!css-loader!sass-loader'
      })
      config.module.rules.push({
        test: /\.js$/,
        loader: 'babel-loader'
      })
      if (isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    },
    vendor: [
      'axios',
      'swiper',
      'element-ui'
    ],
    babel: {
      presets: ['es2015', 'stage-2'],
      plugins: [
        'transform-async-to-generator',
        'transform-runtime'
      ],
      comments: true
    },
    postcss: [
      require('autoprefixer')({
        browsers: ['last 3 versions']
      })
    ]
  },
  css: [
    /* {
    src: 'font-awesome/css/font-awesome.css'
  }, */{src: '~assets/scss/app.scss', lang: 'scss'}
    /* {
      src: 'swiper/dist/css/swiper.css'
    } */ /* , {
      src: 'element-ui/lib/theme-default/index.css'
    } */
  ],
  dev: !isProdMode,
  env: {
    baseUrl
  },
  plugins: [{
    src: '~plugins/axios.js'
  }, {
    src: '~plugins/swiper.js',
    ssr: false
  }, {
    src: '~plugins/vue-loading.js',
    ssr: false
  }, {
    src: '~plugins/vue-empty.js',
    ssr: false
  }, {
    src: '~plugins/element-ui.js',
    ssr: true
  }, {
    src: '~plugins/filters.js',
    ssr: false
  }, {
    src: '~plugins/jsonp.js',
    ssr: false
  }],
  /* TODO 暂时代理到商城测试版，之后再做出调整 */
  proxyTable: ['/api/**', '/search/**', '/user/**', '/login/**', '/register/**', '/logout/**', '/static/**', '/vendor**', '/user**', '/trade/**', '/recommendation/**', '/store-service/**', '/basic/**', '/logout**', '/operation/**', '/help**', '/product**', '/store**', '/order/proxy**', '/report/**', '/store/**#/**', '/kdn/**', '/product/**Submit', '/admin**', '/product/**Submit/**', '/release/**', '/auth/store/**', '/produce/**', '/file**', '/rate/**']
}
