index.ts 2.9 KB

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