index.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { defineConfig, type UserConfigExport } from '@tarojs/cli'
  2. import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
  3. import devConfig from './dev'
  4. import prodConfig from './prod'
  5. import AlipayEventSourceFixPlugin from '../scripts/AlipayEventSourceFixPlugin'
  6. // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
  7. export default defineConfig<'webpack5'>(async (merge, { command, mode }) => {
  8. const baseConfig: UserConfigExport<'webpack5'> = {
  9. projectName: 'payment-mini',
  10. date: '2026-4-9',
  11. designWidth(input) {
  12. // 配置 NutUI 375 尺寸
  13. if (input?.file?.replace(/\\+/g, '/').indexOf('@nutui') > -1) {
  14. return 375
  15. }
  16. // 全局使用 Taro 默认的 750 尺寸
  17. return 750
  18. },
  19. deviceRatio: {
  20. 640: 2.34 / 2,
  21. 750: 1,
  22. 375: 2 / 1,
  23. 828: 1.81 / 2
  24. },
  25. sourceRoot: 'src',
  26. outputRoot: 'dist',
  27. plugins: [
  28. "@tarojs/plugin-generator",
  29. '@tarojs/plugin-html',
  30. ],
  31. defineConstants: {
  32. },
  33. copy: {
  34. patterns: [
  35. ],
  36. options: {
  37. }
  38. },
  39. framework: 'react',
  40. compiler: {
  41. type: 'webpack5',
  42. prebundle: {
  43. enable: false,
  44. exclude: [
  45. '@tarojs/plugin-platform-alipay/dist/runtime',
  46. 'taro-ui',
  47. '@tarojs/taro-alipay',
  48. ]
  49. },
  50. },
  51. cache: {
  52. enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  53. },
  54. mini: {
  55. postcss: {
  56. pxtransform: {
  57. enable: true,
  58. config: {
  59. }
  60. },
  61. cssModules: {
  62. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  63. config: {
  64. namingPattern: 'module', // 转换模式,取值为 global/module
  65. generateScopedName: '[name]__[local]___[hash:base64:5]'
  66. }
  67. }
  68. },
  69. webpackChain(chain) {
  70. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  71. chain.plugin('AlipayEventSourceFixPlugin').use(AlipayEventSourceFixPlugin)
  72. }
  73. },
  74. h5: {
  75. publicPath: '/',
  76. staticDirectory: 'static',
  77. output: {
  78. filename: 'js/[name].[hash:8].js',
  79. chunkFilename: 'js/[name].[chunkhash:8].js'
  80. },
  81. miniCssExtractPluginOption: {
  82. ignoreOrder: true,
  83. filename: 'css/[name].[hash].css',
  84. chunkFilename: 'css/[name].[chunkhash].css'
  85. },
  86. postcss: {
  87. autoprefixer: {
  88. enable: true,
  89. config: {}
  90. },
  91. cssModules: {
  92. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  93. config: {
  94. namingPattern: 'module', // 转换模式,取值为 global/module
  95. generateScopedName: '[name]__[local]___[hash:base64:5]'
  96. }
  97. }
  98. },
  99. webpackChain(chain) {
  100. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  101. }
  102. },
  103. rn: {
  104. appName: 'taroDemo',
  105. postcss: {
  106. cssModules: {
  107. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  108. }
  109. }
  110. }
  111. }
  112. if (process.env.NODE_ENV === 'development') {
  113. // 本地开发构建配置(不混淆压缩)
  114. return merge({}, baseConfig, devConfig)
  115. }
  116. // 生产构建配置(默认开启压缩混淆等)
  117. return merge({}, baseConfig, prodConfig)
  118. })