dev.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type { UserConfigExport } from "@tarojs/cli"
  2. export default {
  3. logger: {
  4. quiet: false,
  5. stats: true
  6. },
  7. compiler: {
  8. type: 'webpack5',
  9. // 关闭开发模式的依赖预编译,减少主包体积以支持微信小程序开发版预览(2MB限制)
  10. // 注意:H5 环境下需要启用 prebundle 以确保 ESM/CJS 模块正确解析
  11. prebundle: {
  12. enable: process.env.TARO_ENV === 'weapp' ? false : true
  13. }
  14. } as any,
  15. mini: {
  16. compile: {
  17. include: [
  18. // 确保产物为 es5,转译所有 node_modules(除了 Babel 核心)
  19. filename => /node_modules\/(?!(@babel|core-js|style-loader|css-loader|react|react-dom))/.test(filename)
  20. ]
  21. }
  22. },
  23. h5: {
  24. devServer: {
  25. port: 10086,
  26. // 配置 HMR WebSocket 端口
  27. client: {
  28. progress: true,
  29. webSocketURL: {
  30. pathname: '/mini-ws',
  31. port: 443, // 指定 HMR WebSocket 端口
  32. },
  33. },
  34. open: false
  35. },
  36. webpackChain(chain) {
  37. // 确保在 HtmlWebpackPlugin 之后添加
  38. chain
  39. .plugin('iframeCommunicationPlugin')
  40. .use(require('webpack-plugin-iframe-communicator').default, [{
  41. hostOrigin: '*',
  42. }])
  43. .after('htmlWebpackPlugin'); // 指定在 htmlWebpackPlugin 之后执行
  44. }
  45. }
  46. } satisfies UserConfigExport<'webpack5'>