const cdn = {
  // 忽略打包的第三方库
  externals: {
    /* vue: 'Vue',
    vuex: 'Vuex',
    axios: 'axios',
    'vue-router': 'VueRouter' */
  },
  // 通过cdn方式使用
  js: [
    /* 'https://cdn.bootcss.com/vue/2.6.12/vue.min.js',
    'https://cdn.bootcss.com/vue-router/3.2.0/vue-router.min.js',
    'https://cdn.bootcss.com/vuex/3.1.1/vuex.min.js',
    'https://cdn.bootcss.com/axios/0.19.2/axios.min.js' */
  ],
  css: []
}

module.exports = {
  publicPath: './',
  devServer: {
    port: 8118,
    open: true,
    proxy: {
      '/api': {
        target: 'https://dapi.auyen.com',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      },
      '/baiduapi': {
        target: 'https://api.map.baidu.com/reverse_geocoding/v3/', // 'http://api.map.baidu.com/geocoder/v2/',
        changeOrigin: true,
        pathRewrite: {
          '^/baiduapi': '/'
        }
      }
    }
  },
  chainWebpack: config => {
    config.plugin('html').tap(args => {
      args[0].cdn = cdn
      return args
    })
    config.plugins.delete('preload')
    config.plugins.delete('prefetch')

    config.module
      .rule('images')
      .use('url-loader')
      .loader('url-loader')
      .tap(options => Object.assign(options, {
        limit: 10240

      })) // 配置图片Base64编码的阀值

    if (process.env.NODE_ENV !== 'development') {
      config.output.filename('js/[name].[contenthash].js').chunkFilename('js/[name].[contenthash].js').end()
    }
  },
  // 打包忽略第三方库
  configureWebpack: {
    externals: cdn.externals
  }
}
