index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import NutUIResolver from '@nutui/auto-import-resolver'
  6. import Components from 'unplugin-vue-components/vite'
  7. // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
  8. export default defineConfig<'vite'>(async (merge, { command, mode }) => {
  9. const baseConfig: UserConfigExport<'vite'> = {
  10. projectName: 'frontui',
  11. date: '2024-12-22',
  12. designWidth (input) {
  13. // 配置 NutUI 375 尺寸
  14. if (input?.file?.replace(/\\+/g, '/').indexOf('@nutui') > -1) {
  15. return 375
  16. }
  17. // 全局使用 Taro 默认的 750 尺寸
  18. return 750
  19. },
  20. deviceRatio: {
  21. 640: 2.34 / 2,
  22. 750: 1,
  23. 375: 2,
  24. 828: 1.81 / 2
  25. },
  26. sourceRoot: 'src',
  27. outputRoot: 'dist',
  28. plugins: ['@tarojs/plugin-html'],
  29. defineConstants: {
  30. },
  31. copy: {
  32. patterns: [
  33. ],
  34. options: {
  35. }
  36. },
  37. framework: 'vue3',
  38. compiler: {
  39. type: 'vite',
  40. vitePlugins: [
  41. Components({
  42. resolvers: [NutUIResolver({taro: true})]
  43. })
  44. ]
  45. },
  46. mini: {
  47. postcss: {
  48. pxtransform: {
  49. enable: true,
  50. config: {
  51. }
  52. },
  53. cssModules: {
  54. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  55. config: {
  56. namingPattern: 'module', // 转换模式,取值为 global/module
  57. generateScopedName: '[name]__[local]___[hash:base64:5]'
  58. }
  59. }
  60. }
  61. },
  62. h5: {
  63. publicPath: '/',
  64. staticDirectory: 'static',
  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. },
  84. rn: {
  85. appName: 'taroDemo',
  86. postcss: {
  87. cssModules: {
  88. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  89. }
  90. }
  91. }
  92. }
  93. if (process.env.NODE_ENV === 'development') {
  94. // 本地开发构建配置(不混淆压缩)
  95. return merge({}, baseConfig, devConfig)
  96. }
  97. // 生产构建配置(默认开启压缩混淆等)
  98. return merge({}, baseConfig, prodConfig)
  99. })