index.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.plugin('weapp-tailwindcss').use(UnifiedWebpackPluginV5, [{
  54. appType: 'taro',
  55. rem2rpx: true
  56. }])
  57. }
  58. },
  59. h5: {
  60. publicPath: '/mini/',
  61. staticDirectory: 'static',
  62. output: {
  63. filename: 'js/[name].[hash:8].js',
  64. chunkFilename: 'js/[name].[chunkhash:8].js'
  65. },
  66. miniCssExtractPluginOption: {
  67. ignoreOrder: true,
  68. filename: 'css/[name].[hash].css',
  69. chunkFilename: 'css/[name].[chunkhash].css'
  70. },
  71. postcss: {
  72. autoprefixer: {
  73. enable: true,
  74. config: {}
  75. },
  76. cssModules: {
  77. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  78. config: {
  79. namingPattern: 'module', // 转换模式,取值为 global/module
  80. generateScopedName: '[name]__[local]___[hash:base64:5]'
  81. }
  82. }
  83. },
  84. webpackChain(chain) {
  85. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  86. },
  87. router: {
  88. basename: '/mini',
  89. },
  90. },
  91. rn: {
  92. appName: 'taroDemo',
  93. postcss: {
  94. cssModules: {
  95. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  96. }
  97. }
  98. }
  99. }
  100. process.env.BROWSERSLIST_ENV = process.env.NODE_ENV
  101. if (process.env.NODE_ENV === 'development') {
  102. // 本地开发构建配置(不混淆压缩)
  103. return merge({}, baseConfig, devConfig)
  104. }
  105. // 生产构建配置(默认开启压缩混淆等)
  106. return merge({}, baseConfig, prodConfig)
  107. })