index.ts 3.1 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<'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. chain.merge({
  76. resolve: {
  77. fallback: {
  78. util: require.resolve('util/'),
  79. stream: require.resolve('stream-browserify'),
  80. fs: require.resolve('browserify-fs'),
  81. path: require.resolve('path-browserify'),
  82. },
  83. },
  84. });
  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. });