const { version } = require('./package.json');
const BASE_URL = '/live/';
const globalEnv = require('./config/global.js');
const modeEnv = process.env.mode ? require(`./config/${process.env.mode}.js`) : {};
const env = { ...globalEnv, ...modeEnv };
const { DEF_S_AODIANYUN, DEF_OSS, X_CA_STAGE, sentryOptions } = env;
const BUILD_DIST = X_CA_STAGE || 'PROD';

export default {
  buildDir: 'nuxt-dist',
  env: {
    baseUrl: BASE_URL,
    ...env
  },
  router: {
    base: BASE_URL,
    middleware: ['device']
  },
  parallel: true,
  cache: true,
  terser: {
    parallel: true,
    cache: true,
    sourceMap: false,
    extractComments: {
      filename: 'LICENSES'
    }
  },
  render: {
    compressor: false,
    http2: {
      push: true
    }
  },
  /*
   ** Headers of the page
   */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { 'http-equiv': 'Cache-control', content: 'no-store no-cache' },
      {
        name: 'viewport',
        content:
          'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no'
      },
      { hid: 'description', name: 'description', content: '现场直播' }
    ],
    link: [{ rel: 'stylesheet', href: `${DEF_OSS}/static/css/reset.css` }],
    script: [
      { src: `${DEF_S_AODIANYUN}/static/jquery/jquery-1.11.1.min.js` },
      { src: `${DEF_S_AODIANYUN}/mps/v1/hlsplayer.js` },
      { src: `${DEF_S_AODIANYUN}/dms/rop_client.js` },
      { src: '//res.wx.qq.com/open/js/jweixin-1.0.0.js' },
      { src: `${DEF_OSS}/static/js/web-animations.min.js` }
    ]
  },
  serverMiddleware: ['@/serverMiddleware/router'],
  /*
   ** Customize the progress-bar color
   */
  loading: { color: '#fff' },
  /*
   ** Global CSS
   */
  css: [],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: ['@/plugins/main.js'],
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: ['@nuxtjs/router'],
  /*
   ** Nuxt.js modules
   */
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/sentry',
    [
      '@nuxtjs/component-cache',
      {
        max: 10000,
        maxAge: 1000 * 60 * 5
      }
    ]
  ],
  sentry: {
    dsn: sentryOptions.dsn,
    config: {}
  },
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0' // default: localhost
  },
  /*
   ** Build configuration
   */
  build: {
    /*
     ** You can extend webpack config here
     */
    // publicPath: `/${BUILD_DIST.toLowerCase()}/`,
    publicPath: process.env.run_server
      ? `//static-${process.env.run_server}.guangdianyun.tv/live/${version}`
      : `/${BUILD_DIST.toLowerCase()}/`,
    extend(config, ctx) {
      // console.log(ctx);
    },
    analyze: false,
    maxChunkSize: 300000,
    plugins: []
  }
};
