import path from "node:path"; import { fileURLToPath } from "node:url"; import { defineConfig, type UserConfigExport } from "@tarojs/cli"; const appRoot = path.resolve(fileURLToPath(new URL("..", import.meta.url))); const DEFAULT_API_BASE_URL = "https://bizwanderq.nianxx.com/api"; class StripWxssWebpackBannersPlugin { apply(compiler: any) { compiler.hooks.thisCompilation.tap("StripWxssWebpackBannersPlugin", (compilation: any) => { compilation.hooks.processAssets.tap( { name: "StripWxssWebpackBannersPlugin", stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE, }, (assets: Record) => { for (const [filename, asset] of Object.entries(assets)) { if (!filename.endsWith(".wxss")) continue; const source = asset.source().toString(); const cleaned = source.replace(/^\/\*![\s\S]*?\*\/\s*/, ""); if (cleaned !== source) { compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(cleaned)); } } }, ); }); } } const baseConfig: UserConfigExport = { projectName: "wanqu-mini-program", date: "2026-07-22", designWidth: 750, deviceRatio: { 640: 2.34 / 2, 750: 1, 828: 1.81 / 2, }, sourceRoot: "src", outputRoot: "dist", framework: "react", compiler: "webpack5", defineConstants: { "process.env.TARO_APP_API_BASE_URL": JSON.stringify(process.env.TARO_APP_API_BASE_URL || DEFAULT_API_BASE_URL), "process.env.TARO_APP_H5_URL": JSON.stringify(process.env.TARO_APP_H5_URL ?? "https://wanderq.nianxx.com"), }, alias: { // Taro 4.2.1 requires React 18. Keep the mini program's renderer on the // workspace-local React copy while H5/admin can continue using React 19. "react$": path.join(appRoot, "node_modules/react"), }, mini: { webpackChain: (chain) => { chain.plugin("strip-wxss-webpack-banners").use(StripWxssWebpackBannersPlugin); }, postcss: { pxtransform: { enable: true }, url: { enable: true }, cssModules: { enable: false }, }, }, h5: { publicPath: "/", staticDirectory: "static", }, }; export default defineConfig(async (merge, _env) => { if (process.env.NODE_ENV === "development") { return merge({}, baseConfig, { mini: { debugReact: true, enableSourceMap: false }, }); } return merge({}, baseConfig); });