const path = require('path')
const isProdMode = Object.is(process.env.NODE_ENV, 'production')
const baseUrl = process.env.BASE_URL || (isProdMode ? 'https://sso.ubtob.com/' : 'http://10.1.51.50:8081/')

module.exports = {
  router: {
    middleware: 'check-auth'
  },
  transition: {
    name: 'fade',
    mode: 'out-in'
  },
  /*
  ** Headers of the page
  */
  head: {
    title: '账户中心',
    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: '账户中心' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/U.png' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: '~components/common/nuxt-loading/Loading.vue',
  /*
  ** 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',
      'element-ui',
      'mint-ui',
      'vuerify',
      'vee-validate'
    ],
    babel: {
      presets: ['es2015', 'stage-2'],
      plugins: [
        'transform-async-to-generator',
        'transform-runtime'
      ],
      comments: true
    },
    postcss: [
      require('autoprefixer')({
        browsers: ['last 3 versions']
      })
    ]
  },
  css: [
    {src: '~assets/scss/mobileCommon.scss', lang: 'scss'},
    {src: '~assets/scss/app.scss', lang: 'scss'}
  ],
  dev: !isProdMode,
  env: {
    baseUrl,
  },
  plugins: [{
    src: '~plugins/axios.js'
  }, {
    src: '~plugins/element-ui.js'
  }, {
    src: '~plugins/mint-ui.js'
  }, {
    src: '~plugins/filters.js',
    ssr: false
  }, {
    src: '~plugins/jsonp.js',
    ssr: false
  }, {
    src: '~plugins/vuerify.js',
    ssr: false
  }, {
    src: '~plugins/vee-validate.js',
    ssr: true
  }],
  /* TODO 暂时代理到商城测试版，之后再做出调整 */
  proxyTable: ['/api/**', '/login/**', '/user**', '/logout**', '/sso/**', '/appeal/**', '/update/user/**', '/valid/**']
}
