import { defineConfig } from '@tarojs/cli'
import path from 'path'

export default defineConfig(async (merge) => {
  const baseConfig = {
    projectName: 'dlbdi-miniapp',
    date: '2026-06-01',
    designWidth: 750,
    deviceRatio: {
      640: 2.34 / 2,
      750: 1,
      828: 1.81 / 2
    },
    sourceRoot: 'src',
    outputRoot: 'dist',
    copy: {
      patterns: [
        {
          from: path.resolve(__dirname, '..', 'src', 'skills'),
          to: path.resolve(__dirname, '..', 'dist', 'skills'),
          ignore: ['**/._*', '**/.DS_Store']
        },
        {
          from: path.resolve(__dirname, '..', 'src', 'page-meta.json'),
          to: path.resolve(__dirname, '..', 'dist', 'page-meta.json'),
          ignore: ['**/._*', '**/.DS_Store']
        },
        {
          from: path.resolve(__dirname, '..', 'src', 'native-components'),
          to: path.resolve(__dirname, '..', 'dist', 'native-components'),
          ignore: ['**/._*', '**/.DS_Store']
        }
      ],
      options: {
        ignore: ['**/._*', '**/.DS_Store']
      }
    },
    alias: {
      '@': path.resolve(__dirname, '..', 'src')
    },
    framework: 'react',
    compiler: 'webpack5',
    mini: {},
    h5: {
      publicPath: '/',
      staticDirectory: 'static',
      router: {
        mode: 'browser'
      }
    }
  }

  if (process.env.NODE_ENV === 'production') {
    return merge({}, baseConfig, (await import('./prod')).default)
  }

  return merge({}, baseConfig, (await import('./dev')).default)
})
