index.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { defineConfig } 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) => {
  7. const baseConfig = {
  8. projectName: 'miniprogram-lineforfun',
  9. date: '2023-8-13',
  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: 'react',
  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. sassLoaderOption: {
  55. sassOptions: {
  56. outputStyle: 'expanded'
  57. }
  58. },
  59. miniCssExtractPluginOption: {
  60. ignoreOrder: true,
  61. },
  62. },
  63. h5: {
  64. publicPath: '/',
  65. staticDirectory: 'static',
  66. output: {
  67. filename: 'js/[name].[hash:8].js',
  68. chunkFilename: 'js/[name].[chunkhash:8].js'
  69. },
  70. miniCssExtractPluginOption: {
  71. ignoreOrder: true,
  72. filename: 'css/[name].[hash:8].css',
  73. chunkFilename: 'css/[name].[chunkhash:8].css'
  74. },
  75. postcss: {
  76. autoprefixer: {
  77. enable: true,
  78. config: {}
  79. },
  80. cssModules: {
  81. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  82. config: {
  83. namingPattern: 'module', // 转换模式,取值为 global/module
  84. generateScopedName: '[name]__[local]___[hash:base64:5]'
  85. }
  86. }
  87. },
  88. webpackChain(chain) {
  89. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  90. }
  91. },
  92. rn: {
  93. appName: 'taroDemo',
  94. postcss: {
  95. cssModules: {
  96. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  97. }
  98. }
  99. }
  100. }
  101. if (process.env.NODE_ENV === 'development') {
  102. // 本地开发构建配置
  103. return merge({}, baseConfig, devConfig)
  104. }
  105. // 生产构建配置
  106. return merge({}, baseConfig, prodConfig)
  107. })