index.ts 2.8 KB

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