dev.ts 1.2 KB

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