index.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { defineConfig, type UserConfigExport } from '@tarojs/cli'
  2. import { UnifiedWebpackPluginV5 } from 'weapp-tailwindcss/webpack'
  3. import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
  4. import devConfig from './dev'
  5. import prodConfig from './prod'
  6. import path from 'path'
  7. // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
  8. export default defineConfig(async (merge, { command, mode }) => {
  9. const baseConfig: UserConfigExport = {
  10. projectName: 'miniLeaf',
  11. date: '2024-8-26',
  12. designWidth: 375,
  13. deviceRatio: {
  14. 640: 2.34 / 2,
  15. 750: 1,
  16. 375: 2 / 1,
  17. 828: 1.81 / 2
  18. },
  19. alias: {
  20. '@': path.resolve(__dirname, '..', 'src'),
  21. },
  22. sourceRoot: 'src',
  23. outputRoot: 'dist',
  24. plugins: ['@taro-hooks/plugin-react', '@tarojs/plugin-http'],
  25. defineConstants: {
  26. },
  27. copy: {
  28. patterns: [
  29. ],
  30. options: {
  31. }
  32. },
  33. framework: 'react',
  34. compiler: {
  35. type: 'webpack5',
  36. prebundle: {
  37. enable: false
  38. }
  39. },
  40. cache: {
  41. enable: true // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  42. },
  43. url: {
  44. enable: true,
  45. config: {
  46. limit: 10240 // 设定转换尺寸上限
  47. }
  48. },
  49. mini: {
  50. // 无语,前期好好的,突然就出现了这个错误,
  51. // 编译警告,Error: chunk common [mini-css-extract-plugin] Conflicting order. Following module has been added:
  52. // 需要如下配置 miniCssExtractPluginOption
  53. miniCssExtractPluginOption: {
  54. ignoreOrder: true
  55. },
  56. postcss: {
  57. pxtransform: {
  58. enable: true,
  59. config: {
  60. }
  61. },
  62. url: {
  63. enable: true,
  64. config: {
  65. limit: 1024 // 设定转换尺寸上限
  66. }
  67. },
  68. cssModules: {
  69. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  70. config: {
  71. namingPattern: 'module', // 转换模式,取值为 global/module
  72. generateScopedName: '[name]__[local]___[hash:base64:5]'
  73. }
  74. }
  75. },
  76. webpackChain(chain) {
  77. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  78. chain.merge({
  79. plugin: {
  80. install: {
  81. plugin: UnifiedWebpackPluginV5,
  82. args: [{
  83. appType: 'taro'
  84. }]
  85. }
  86. }
  87. })
  88. }
  89. },
  90. h5: {
  91. publicPath: '/',
  92. staticDirectory: 'static',
  93. devServer:{
  94. https: true,
  95. },
  96. output: {
  97. filename: 'js/[name].[hash:8].js',
  98. chunkFilename: 'js/[name].[chunkhash:8].js'
  99. },
  100. router: {
  101. mode:"browser",
  102. },
  103. miniCssExtractPluginOption: {
  104. ignoreOrder: true,
  105. filename: 'css/[name].[hash].css',
  106. chunkFilename: 'css/[name].[chunkhash].css'
  107. },
  108. postcss: {
  109. autoprefixer: {
  110. enable: true,
  111. config: {}
  112. },
  113. cssModules: {
  114. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  115. config: {
  116. namingPattern: 'module', // 转换模式,取值为 global/module
  117. generateScopedName: '[name]__[local]___[hash:base64:5]'
  118. }
  119. }
  120. },
  121. webpackChain(chain) {
  122. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  123. }
  124. },
  125. rn: {
  126. appName: 'taroDemo',
  127. postcss: {
  128. cssModules: {
  129. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  130. }
  131. }
  132. }
  133. }
  134. if (process.env.NODE_ENV === 'development') {
  135. // 本地开发构建配置(不混淆压缩)
  136. return merge({}, baseConfig, devConfig)
  137. }
  138. // 生产构建配置(默认开启压缩混淆等)
  139. return merge({}, baseConfig, prodConfig)
  140. })