index.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { defineConfig, type UserConfigExport } from '@tarojs/cli'
  2. import devConfig from './dev'
  3. import prodConfig from './prod'
  4. // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
  5. export default defineConfig<'vite'>(async merge => {
  6. const baseConfig: UserConfigExport<'vite'> = {
  7. projectName: 'app',
  8. date: '2026-5-6',
  9. designWidth: 750,
  10. deviceRatio: {
  11. 640: 2.34 / 2,
  12. 750: 1,
  13. 375: 2,
  14. 828: 1.81 / 2
  15. },
  16. sourceRoot: 'src',
  17. outputRoot: 'dist',
  18. plugins: [
  19. "@tarojs/plugin-generator"
  20. ],
  21. defineConstants: {
  22. },
  23. copy: {
  24. patterns: [
  25. ],
  26. options: {
  27. }
  28. },
  29. framework: 'vue3',
  30. compiler: 'vite',
  31. mini: {
  32. postcss: {
  33. pxtransform: {
  34. enable: true,
  35. config: {
  36. }
  37. },
  38. cssModules: {
  39. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  40. config: {
  41. namingPattern: 'module', // 转换模式,取值为 global/module
  42. generateScopedName: '[name]__[local]___[hash:base64:5]'
  43. }
  44. }
  45. },
  46. },
  47. h5: {
  48. publicPath: '/',
  49. staticDirectory: 'static',
  50. miniCssExtractPluginOption: {
  51. ignoreOrder: true,
  52. filename: 'css/[name].[hash].css',
  53. chunkFilename: 'css/[name].[chunkhash].css'
  54. },
  55. postcss: {
  56. autoprefixer: {
  57. enable: true,
  58. config: {}
  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. },
  69. rn: {
  70. appName: 'taroDemo',
  71. postcss: {
  72. cssModules: {
  73. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  74. }
  75. }
  76. }
  77. }
  78. if (process.env.NODE_ENV === 'development') {
  79. // 本地开发构建配置(不混淆压缩)
  80. return merge({}, baseConfig, devConfig)
  81. }
  82. // 生产构建配置(默认开启压缩混淆等)
  83. return merge({}, baseConfig, prodConfig)
  84. })