index.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { defineConfig } from '@tarojs/cli'
  2. import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
  3. // 导入sass
  4. import * as sass from 'sass'
  5. import devConfig from './dev'
  6. import prodConfig from './prod'
  7. // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
  8. export default defineConfig(async (merge) => {
  9. const baseConfig = {
  10. projectName: 'miniprogram-lineforfun',
  11. date: '2023-8-13',
  12. designWidth: 750,
  13. deviceRatio: {
  14. 640: 2.34 / 2,
  15. 750: 1,
  16. 375: 2,
  17. 828: 1.81 / 2
  18. },
  19. sourceRoot: 'src',
  20. outputRoot: 'dist',
  21. plugins: [],
  22. defineConstants: {
  23. },
  24. copy: {
  25. patterns: [
  26. ],
  27. options: {
  28. }
  29. },
  30. framework: 'react',
  31. compiler: 'webpack5',
  32. cache: {
  33. enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  34. },
  35. mini: {
  36. postcss: {
  37. pxtransform: {
  38. enable: true,
  39. config: {
  40. }
  41. },
  42. url: {
  43. enable: true,
  44. config: {
  45. limit: 1024 // 设定转换尺寸上限
  46. }
  47. },
  48. cssModules: {
  49. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  50. config: {
  51. namingPattern: 'module', // 转换模式,取值为 global/module
  52. generateScopedName: '[name]__[local]___[hash:base64:5]'
  53. }
  54. }
  55. },
  56. sassLoaderOption: {
  57. sassOptions: {
  58. outputStyle: 'expanded'
  59. }
  60. },
  61. miniCssExtractPluginOption: {
  62. ignoreOrder: true,
  63. },
  64. },
  65. h5: {
  66. publicPath: '/',
  67. staticDirectory: 'static',
  68. output: {
  69. filename: 'js/[name].[hash:8].js',
  70. chunkFilename: 'js/[name].[chunkhash:8].js'
  71. },
  72. miniCssExtractPluginOption: {
  73. ignoreOrder: true,
  74. filename: 'css/[name].[hash:8].css',
  75. chunkFilename: 'css/[name].[chunkhash:8].css'
  76. },
  77. postcss: {
  78. autoprefixer: {
  79. enable: true,
  80. config: {}
  81. },
  82. cssModules: {
  83. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  84. config: {
  85. namingPattern: 'module', // 转换模式,取值为 global/module
  86. generateScopedName: '[name]__[local]___[hash:base64:5]'
  87. }
  88. }
  89. },
  90. webpackChain(chain) {
  91. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  92. }
  93. },
  94. rn: {
  95. appName: 'taroDemo',
  96. postcss: {
  97. cssModules: {
  98. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  99. }
  100. }
  101. }
  102. }
  103. if (process.env.NODE_ENV === 'development') {
  104. // 本地开发构建配置
  105. return merge({}, baseConfig, devConfig)
  106. }
  107. // 生产构建配置
  108. return merge({}, baseConfig, prodConfig)
  109. })