const { resolve } = require('path')
const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  publicPath: '/',
  lintOnSave: false,
  // 打包时不生成.map文件
  productionSourceMap: false,
  chainWebpack: (config) => {
    config.module.rule('svg').exclude.add(resolve('src/icons')).end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
    config.plugin('html')
      .tap(args => {
        args[0].title = "Extensive Imaging";
        return args;
      })
  },
  configureWebpack: {
    devtool: 'source-map',
    output: {
      filename: `static/js/[name].[contenthash:8].js`,
      chunkFilename: `static/js/[name].[chunkhash:8].js`,
      assetModuleFilename: 'static/wasm/[name].[contenthash:8][ext]'
    },
    resolve: {
      extensions: ['.js', '.vue', '.json'], // 当引入文件时默认先找.js后缀的文件，没找到再从左往右继续
      alias: {
        vue$: 'vue/dist/vue.esm.js',
        '@': resolve('src')
      }
    },
    plugins: [

    ],
    performance: {
      hints: false
    },
    module: {
      rules: [
      ]
    }
  },
  devServer: {
    // https: true,
    host: '0.0.0.0',
    port: 9528,
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://123.56.94.154:9530',
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: '/api/v1'
        }
      },
      '/img_url': {
        target: 'http://123.56.94.154:9530',
        changeOrigin: true,
        pathRewrite: {
          '^/img_url': ''
        }
      }
    }
  }
})

