index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const path = require('path')
  2. const { version } = require('../package.json')
  3. const CIPluginOpt = {
  4. weapp: {
  5. appid: process.env.WEAPP_ID || '微信小程序appid',
  6. privateKeyPath: "key/private.appid.key"
  7. },
  8. tt: {
  9. email: "字节小程序邮箱",
  10. password: "字节小程序密码"
  11. },
  12. alipay: {
  13. appid: "支付宝小程序appId",
  14. toolId: "工具id",
  15. privateKeyPath: "key/pkcs8-private-pem"
  16. },
  17. swan: {
  18. token: "鉴权需要的token令牌"
  19. },
  20. version,
  21. desc: "修复已知问题"
  22. }
  23. const plugins = process.env.TARO_ENV === 'weapp' ? [
  24. [ "@tarojs/plugin-mini-ci", CIPluginOpt ],
  25. [ "@tarojs/plugin-html"]
  26. ] : []
  27. const config = {
  28. projectName: '蚁群互动',
  29. date: '2025-08-01',
  30. designWidth: 750,
  31. deviceRatio: {
  32. 640: 2.34 / 2,
  33. 750: 1,
  34. 828: 1.81 / 2
  35. },
  36. sourceRoot: 'src',
  37. outputRoot: 'dist',
  38. plugins,
  39. defineConstants: {
  40. },
  41. copy: {
  42. patterns: [
  43. ],
  44. options: {
  45. }
  46. },
  47. framework: 'react',
  48. compiler: 'webpack5',
  49. mini: {
  50. postcss: {
  51. pxtransform: {
  52. enable: true,
  53. config: {
  54. }
  55. },
  56. url: {
  57. enable: true,
  58. config: {
  59. limit: 1024 // 设定转换尺寸上限
  60. }
  61. },
  62. cssModules: {
  63. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  64. config: {
  65. namingPattern: 'module', // 转换模式,取值为 global/module
  66. generateScopedName: '[name]__[local]___[hash:base64:5]'
  67. }
  68. }
  69. }
  70. },
  71. h5: {
  72. publicPath: '/h5/',
  73. staticDirectory: 'static',
  74. postcss: {
  75. autoprefixer: {
  76. enable: true,
  77. config: {
  78. }
  79. },
  80. cssModules: {
  81. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  82. config: {
  83. namingPattern: 'module', // 转换模式,取值为 global/module
  84. generateScopedName: '[name]__[local]___[hash:base64:5]'
  85. }
  86. }
  87. },
  88. webpackChain(chain) {
  89. chain.output.path(path.resolve(__dirname, '..', 'dist', 'h5'));
  90. // 排除 react-native 模块
  91. chain.resolve.alias
  92. .set('react-native', false)
  93. .set('react-native-webview', false)
  94. .set('@react-navigation/native', false)
  95. .set('react-native-signature-canvas', false)
  96. }
  97. },
  98. rn: {
  99. appName: 'taroDemo',
  100. bundleOptions: {
  101. dev: false, // 生产环境必须为 false
  102. lazy: false,
  103. minify: true, // 生产环境启用压缩
  104. },
  105. output: {
  106. ios: './ios/main.jsbundle',
  107. iosAssetsDest: './ios',
  108. android: './android/app/src/main/assets/index.android.bundle',
  109. androidAssetsDest: './android/app/src/main/res',
  110. // iosSourceMapUrl: '',
  111. iosSourcemapOutput: './ios/main.map',
  112. // iosSourcemapSourcesRoot: '',
  113. // androidSourceMapUrl: '',
  114. androidSourcemapOutput: './android/app/src/main/assets/index.android.map',
  115. // androidSourcemapSourcesRoot: '',
  116. },
  117. sass: {
  118. additionalData: '@use "sass:math";'
  119. },
  120. postcss: {
  121. cssModules:{
  122. enable: true,
  123. }
  124. },
  125. staticAssets: {
  126. // 配置需要复制到原生项目的静态资源
  127. copyOptions: {
  128. patterns: [
  129. {
  130. from: 'src/web-resources', // 你的静态资源源目录
  131. to: 'android/app/src/main/assets/web-resources', // 目标目录
  132. },
  133. ],
  134. },
  135. }
  136. },
  137. alias: {
  138. '@': path.resolve(__dirname, '..', 'src'),
  139. }
  140. }
  141. module.exports = function (merge) {
  142. if (process.env.NODE_ENV === 'development') {
  143. return merge({}, config, require('./dev'))
  144. }
  145. return merge({}, config, require('./prod'))
  146. }