index.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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(async (merge, { command, mode }) => {
  7. const baseConfig: UserConfigExport = {
  8. projectName: 'shaoershuhua',
  9. date: '2024-2-29',
  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. defineConstants: {
  21. },
  22. copy: {
  23. patterns: [
  24. ],
  25. options: {
  26. }
  27. },
  28. framework: 'preact',
  29. compiler: 'webpack5',
  30. cache: {
  31. enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  32. },
  33. mini: {
  34. postcss: {
  35. pxtransform: {
  36. enable: true,
  37. config: {
  38. }
  39. },
  40. url: {
  41. enable: true,
  42. config: {
  43. limit: 1024 // 设定转换尺寸上限
  44. }
  45. },
  46. cssModules: {
  47. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  48. config: {
  49. namingPattern: 'module', // 转换模式,取值为 global/module
  50. generateScopedName: '[name]__[local]___[hash:base64:5]'
  51. }
  52. }
  53. },
  54. webpackChain(chain) {
  55. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  56. }
  57. },
  58. h5: {
  59. publicPath: '/',
  60. staticDirectory: 'static',
  61. output: {
  62. filename: 'js/[name].[hash:8].js',
  63. chunkFilename: 'js/[name].[chunkhash:8].js'
  64. },
  65. miniCssExtractPluginOption: {
  66. ignoreOrder: true,
  67. filename: 'css/[name].[hash].css',
  68. chunkFilename: 'css/[name].[chunkhash].css'
  69. },
  70. postcss: {
  71. autoprefixer: {
  72. enable: true,
  73. config: {}
  74. },
  75. cssModules: {
  76. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  77. config: {
  78. namingPattern: 'module', // 转换模式,取值为 global/module
  79. generateScopedName: '[name]__[local]___[hash:base64:5]'
  80. }
  81. }
  82. },
  83. webpackChain(chain) {
  84. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  85. }
  86. },
  87. rn: {
  88. appName: 'taroDemo',
  89. postcss: {
  90. cssModules: {
  91. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  92. }
  93. }
  94. }
  95. }
  96. if (process.env.NODE_ENV === 'development') {
  97. // 本地开发构建配置(不混淆压缩)
  98. return merge({}, baseConfig, devConfig)
  99. }
  100. // 生产构建配置(默认开启压缩混淆等)
  101. return merge({}, baseConfig, prodConfig)
  102. })