2
0

index.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { defineConfig, type UserConfigExport } from '@tarojs/cli'
  2. import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
  3. import { UnifiedWebpackPluginV5 } from 'weapp-tailwindcss/webpack'
  4. import devConfig from './dev'
  5. import prodConfig from './prod'
  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: 'mini',
  10. date: '2025-7-27',
  11. designWidth: 750,
  12. deviceRatio: {
  13. 640: 2.34 / 2,
  14. 750: 1,
  15. 375: 2,
  16. 828: 1.81 / 2
  17. },
  18. sourceRoot: 'src',
  19. outputRoot: 'dist',
  20. plugins: [
  21. "@tarojs/plugin-generator"
  22. ],
  23. defineConstants: {
  24. },
  25. copy: {
  26. patterns: [
  27. ],
  28. options: {
  29. }
  30. },
  31. framework: 'react',
  32. compiler: 'webpack5',
  33. cache: {
  34. enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  35. },
  36. mini: {
  37. postcss: {
  38. pxtransform: {
  39. enable: true,
  40. config: {
  41. }
  42. },
  43. cssModules: {
  44. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  45. config: {
  46. namingPattern: 'module', // 转换模式,取值为 global/module
  47. generateScopedName: '[name]__[local]___[hash:base64:5]'
  48. }
  49. }
  50. },
  51. webpackChain(chain) {
  52. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  53. chain.merge({
  54. plugin: {
  55. install: {
  56. plugin: UnifiedWebpackPluginV5,
  57. args: [{
  58. // 这里可以传参数
  59. }]
  60. }
  61. }
  62. })
  63. }
  64. },
  65. h5: {
  66. publicPath: '/mini/',
  67. staticDirectory: 'static',
  68. output: {
  69. filename: 'js/[name].[hash:8].js',
  70. chunkFilename: 'js/[name].[chunkhash:8].js'
  71. },
  72. miniCssExtractPluginOption: {
  73. ignoreOrder: true,
  74. filename: 'css/[name].[hash].css',
  75. chunkFilename: 'css/[name].[chunkhash].css'
  76. },
  77. postcss: {
  78. autoprefixer: {
  79. enable: true,
  80. config: {}
  81. },
  82. cssModules: {
  83. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  84. config: {
  85. namingPattern: 'module', // 转换模式,取值为 global/module
  86. generateScopedName: '[name]__[local]___[hash:base64:5]'
  87. }
  88. }
  89. },
  90. webpackChain(chain) {
  91. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  92. },
  93. router: {
  94. basename: '/mini',
  95. },
  96. },
  97. rn: {
  98. appName: 'taroDemo',
  99. postcss: {
  100. cssModules: {
  101. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  102. }
  103. }
  104. }
  105. }
  106. process.env.BROWSERSLIST_ENV = process.env.NODE_ENV
  107. if (process.env.NODE_ENV === 'development') {
  108. // 本地开发构建配置(不混淆压缩)
  109. return merge({}, baseConfig, devConfig)
  110. }
  111. // 生产构建配置(默认开启压缩混淆等)
  112. return merge({}, baseConfig, prodConfig)
  113. })