import { defineConfig } from "@tarojs/cli";

const isWeapp = process.env.TARO_ENV === "weapp";
const isProd = process.env.NODE_ENV === "production";
const defaultApiBase = isWeapp
  ? (isProd ? "https://dlxlh.dtacloud.cn" : "http://127.0.0.1:8082")
  : "http://localhost:8082";
const apiBase = process.env.TARO_APP_API_BASE || defaultApiBase;
const uploadPublicBase = process.env.TARO_APP_UPLOAD_BASE || apiBase;

export default defineConfig({
  projectName: "wx_taro",
  date: "2026-05-12",
  designWidth: 375,
  deviceRatio: {
    375: 2,
    750: 1,
    828: 1.81
  },
  sourceRoot: "src",
  outputRoot: "dist",
  plugins: [],
  defineConstants: {
    __API_BASE__: JSON.stringify(apiBase),
    __UPLOAD_PUBLIC_BASE__: JSON.stringify(uploadPublicBase)
  },
  copy: {
    patterns: [
      { from: "src/skills", to: "dist/skills", ignore: ["**/._*"] },
      { from: "src/page-meta.json", to: "dist/page-meta.json" }
    ],
    options: {}
  },
  framework: "react",
  compiler: "webpack5",
  cache: { enable: false },
  mini: {
    postcss: {
      pxtransform: { enable: true, config: {} },
      url: { enable: true, config: { limit: 1024 } },
      cssModules: { enable: false, config: { namingPattern: "module", generateScopedName: "[name]__[local]___[hash:base64:5]" } }
    }
  },
  h5: {
    publicPath: "/",
    staticDirectory: "static",
    postcss: {
      autoprefixer: { enable: true, config: {} },
      cssModules: { enable: false, config: { namingPattern: "module", generateScopedName: "[name]__[local]___[hash:base64:5]" } }
    }
  }
});
