import path from 'node:path'; import { defineConfig } from '@tarojs/cli'; /** 小程序/H5 请求的后端 origin(不含 /api);本地联调可用 VITE_API_TARGET 覆盖 */ const API_ORIGIN = process.env.VITE_API_TARGET ?? 'https://dkapi.runxian.top'; export default defineConfig(async () => ({ projectName: 'mini-user', date: '2026-7-12', designWidth: 375, deviceRatio: { 640: 2.34 / 2, 750: 1, 375: 2, 828: 1.81 / 2, }, sourceRoot: 'src', outputRoot: 'dist', plugins: ['@tarojs/plugin-framework-react', '@tarojs/plugin-html'], alias: { react: path.resolve(__dirname, '../node_modules/react'), 'react-dom': path.resolve(__dirname, '../node_modules/react-dom'), }, defineConstants: { TARO_APP_API_ORIGIN: JSON.stringify(API_ORIGIN), }, copy: { patterns: [ { from: 'src/assets/', to: 'assets/' }, ], options: {}, }, framework: 'react', compiler: { type: 'vite', vitePlugins: [ { name: 'dukang-mini-user-vite-memory', config() { return { // H5 Vite watch 预构建 Stencil 组件时峰值极易 >8GB;noDiscovery 降低冷启动成本 optimizeDeps: { noDiscovery: true, include: ['react', 'react-dom', 'react/jsx-runtime'], }, build: { sourcemap: false, }, }; }, }, ], }, cache: { enable: true, }, mini: { /** dev:weapp 预览模式需开启,否则 React hooks 在 Vite 下会失效 */ debugReact: process.env.NODE_ENV !== 'production', postcss: { pxtransform: { enable: true, config: {} }, cssModules: { enable: false }, }, }, h5: { publicPath: '/', staticDirectory: 'static', devServer: { port: 5177, host: '0.0.0.0', proxy: { '/api': { target: API_ORIGIN, changeOrigin: true, }, }, }, postcss: { autoprefixer: { enable: true, config: {} }, pxtransform: { enable: true, config: {} }, cssModules: { enable: false }, }, }, }));