import type { UserConfigExport } from "@tarojs/cli" export default { logger: { quiet: false, stats: true }, compiler: { type: 'webpack5', // 关闭开发模式的依赖预编译,减少主包体积以支持微信小程序开发版预览(2MB限制) // 注意:H5 环境下需要启用 prebundle 以确保 ESM/CJS 模块正确解析 prebundle: { enable: process.env.TARO_ENV === 'weapp' ? false : true } } as any, mini: { compile: { include: [ // 确保产物为 es5,转译所有 node_modules(除了 Babel 核心) filename => /node_modules\/(?!(@babel|core-js|style-loader|css-loader|react|react-dom))/.test(filename) ] } }, h5: { devServer: { port: 10086, // 配置 HMR WebSocket 端口 client: { progress: true, webSocketURL: { pathname: '/mini-ws', port: 443, // 指定 HMR WebSocket 端口 }, }, open: false }, webpackChain(chain) { // 确保在 HtmlWebpackPlugin 之后添加 chain .plugin('iframeCommunicationPlugin') .use(require('webpack-plugin-iframe-communicator').default, [{ hostOrigin: '*', }]) .after('htmlWebpackPlugin'); // 指定在 htmlWebpackPlugin 之后执行 } } } satisfies UserConfigExport<'webpack5'>