'use strict'
const path = require('path')
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin')

function resolve (dir) {
  return path.join(__dirname, dir)
}

const outputDir = path.join(path.resolve(__dirname, '../../..'), 'public/code')

const name = '外贸易-在线编辑' // page title

const port = process.env.port || process.env.npm_config_port || 3075 // dev port

module.exports = {

  publicPath: process.env.VUE_APP_BASE_URL,
  outputDir: outputDir,
  assetsDir: process.env.VUE_APP_STATIC,
  lintOnSave: process.env.NODE_ENV === 'development',
  productionSourceMap: false,
  devServer: {
    port: port,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      '/admin': {
        target: 'http://www.waimao.test/admin',
        changeOrigin: true,
        pathRewrite: {
          '^/admin': ''
        }
      }
    },
    // 解决 sockjs-node 接口报错
    // public: 'http://sanji.lanyun.test:9529',
    // 解决 sockjs-node 一直请求接口
    disableHostCheck: true
  },
  css: {
    loaderOptions: {
      sass: {
        implementation: require('sass'),
      }
    }
  },
  configureWebpack: config => {
    config.name = name;
    config.resolve.alias['@'] = resolve('src')
    config.plugins.push(new MonacoEditorPlugin())
  },
  chainWebpack (config) {
    // set svg-sprite-loader
    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()
  },
  transpileDependencies: [
    'vue-echarts',
    'resize-detector'
  ]
}
