const settings = require('./src/settings')
const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}

// 移除 defineConfig 包裹（兼容旧版）
module.exports = {
  assetsDir: 'static',
  runtimeCompiler: true,
  
  // 关键修复：转译现代语法依赖
  transpileDependencies: [
    /@vue\/devtools-kit/,
    /birpc/,
    /@vue\/devtools-api/,
    /vee-validate/
  ],

  css: {
    requireModuleExtension: true,
    sourceMap: process.env.NODE_ENV === 'development'
  },

  configureWebpack: {
    name: settings.title,
    resolve: {
      extensions: ['.js', '.vue', '.json', '.mjs'],
      alias: { '@': resolve('src') }
    },
    module: {
      rules: [
        {
          test: /\.m?js$/,
          include: /node_modules\/(@vue\/devtools-kit|birpc)/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env'],
              plugins: [
                '@babel/plugin-proposal-optional-chaining'
              ]
            }
          }
        },
        {
          test: /\.mjs$/,
          include: /node_modules/,
          type: "javascript/auto"
        }
      ]
    },
    plugins: [
      require('unplugin-vue-components/webpack')({
        resolvers: [require('unplugin-vue-components/resolvers').ElementPlusResolver()]
      })
    ]
  },

  chainWebpack: config => {
    // 生产环境移除console
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer('terser').tap(args => {
        args[0].terserOptions.compress.drop_console = true
        return args
      })
    }
  },

  devServer: {
    host: 'swt.costapi.f2b211.com',
    https: true,
    hot: true
  }
}