index.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. ],
  30. defineConstants: {
  31. },
  32. copy: {
  33. patterns: [
  34. ],
  35. options: {
  36. }
  37. },
  38. framework: 'react',
  39. compiler: {
  40. type: 'webpack5',
  41. prebundle: {
  42. enable: false,
  43. exclude: [
  44. '@tarojs/plugin-platform-alipay/dist/runtime',
  45. 'taro-ui',
  46. '@tarojs/taro-alipay',
  47. ]
  48. },
  49. },
  50. cache: {
  51. enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  52. },
  53. mini: {
  54. postcss: {
  55. pxtransform: {
  56. enable: true,
  57. config: {
  58. }
  59. },
  60. cssModules: {
  61. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  62. config: {
  63. namingPattern: 'module', // 转换模式,取值为 global/module
  64. generateScopedName: '[name]__[local]___[hash:base64:5]'
  65. }
  66. }
  67. },
  68. webpackChain(chain) {
  69. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  70. chain.plugin('AlipayEventSourceFixPlugin').use(AlipayEventSourceFixPlugin)
  71. }
  72. },
  73. h5: {
  74. publicPath: '/',
  75. staticDirectory: 'static',
  76. output: {
  77. filename: 'js/[name].[hash:8].js',
  78. chunkFilename: 'js/[name].[chunkhash:8].js'
  79. },
  80. miniCssExtractPluginOption: {
  81. ignoreOrder: true,
  82. filename: 'css/[name].[hash].css',
  83. chunkFilename: 'css/[name].[chunkhash].css'
  84. },
  85. postcss: {
  86. autoprefixer: {
  87. enable: true,
  88. config: {}
  89. },
  90. cssModules: {
  91. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  92. config: {
  93. namingPattern: 'module', // 转换模式,取值为 global/module
  94. generateScopedName: '[name]__[local]___[hash:base64:5]'
  95. }
  96. }
  97. },
  98. webpackChain(chain) {
  99. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  100. }
  101. },
  102. rn: {
  103. appName: 'taroDemo',
  104. postcss: {
  105. cssModules: {
  106. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  107. }
  108. }
  109. }
  110. }
  111. if (process.env.NODE_ENV === 'development') {
  112. // 本地开发构建配置(不混淆压缩)
  113. return merge({}, baseConfig, devConfig)
  114. }
  115. // 生产构建配置(默认开启压缩混淆等)
  116. return merge({}, baseConfig, prodConfig)
  117. })