index.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { defineConfig } from "@tarojs/cli";
  2. const path = require("path");
  3. import devConfig from "./dev";
  4. import prodConfig from "./prod";
  5. const url = "http://127.0.0.1:9087";
  6. export default defineConfig(async (merge, { command, mode }) => {
  7. const config = {
  8. projectName: "civilized-miniapp",
  9. date: "2024-03-21",
  10. designWidth(input) {
  11. console.log('---->', input?.file)
  12. // if (input?.file.replace(/\\+/g, '/').indexOf('@antmjs/vantui') > -1) {
  13. // return 750
  14. // }
  15. return 750
  16. },
  17. deviceRatio: {
  18. 640: 2.34 / 2,
  19. 750: 1,
  20. 828: 1.81 / 2,
  21. 375: 2 / 1,
  22. },
  23. sourceRoot: "src",
  24. outputRoot: "dist",
  25. plugins: [],
  26. defineConstants: {},
  27. copy: {
  28. patterns: [{ from: "src/assets/tabbar/", to: "dist/assets/tabbar/" }],
  29. options: {},
  30. },
  31. framework: "react",
  32. compiler: "webpack4",
  33. alias: {
  34. "@": path.resolve(__dirname, "..", "src"),
  35. },
  36. // mini: {
  37. // postcss: {
  38. // pxtransform: {
  39. // enable: true,
  40. // config: {},
  41. // },
  42. // url: {
  43. // enable: true,
  44. // config: {
  45. // limit: 1024, // 设定转换尺寸上限
  46. // },
  47. // },
  48. // cssModules: {
  49. // enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  50. // config: {
  51. // namingPattern: "module", // 转换模式,取值为 global/module
  52. // generateScopedName: "[name]__[local]___[hash:base64:5]",
  53. // },
  54. // },
  55. // },
  56. // },
  57. h5: {
  58. publicPath: "/",
  59. staticDirectory: "static",
  60. outputDir: "dist",
  61. router: {
  62. mode: "hash",
  63. },
  64. esnextModules: ['@antmjs'],
  65. // miniCssExtractPluginOption: {
  66. // ignoreOrder: true,
  67. // filename: "css/[name].[hash].css",
  68. // chunkFilename: "css/[id].css",
  69. // },
  70. postcss: {
  71. autoprefixer: {
  72. enable: true,
  73. config: {
  74. }
  75. },
  76. pxtransform: {
  77. enable: true,
  78. config: {
  79. // 设置rpx转换为目标单位为rem
  80. // unitToRem: true,
  81. // // 设计稿宽度与 rem 基准值,默认设计稿宽度为 750,即 1rem = 75px
  82. // designWidth: 750,
  83. // // 可选,选择器黑名单
  84. // selectorBlackList: [],
  85. // // // 可选,替换rpx为其他单位后缀,例如 'px' 或 'rem'
  86. // propList: ["*"],
  87. // // 可选,媒体查询中是否禁用转换
  88. // mediaQuery: false,
  89. // // 可选,是否转换页面根节点字体大小,如body: font-size: 16px
  90. // minPixelValue: 0,
  91. },
  92. },
  93. cssModules: {
  94. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  95. config: {
  96. namingPattern: "module", // 转换模式,取值为 global/module,下文详细说明
  97. generateScopedName: "[name]__[local]___[hash:base64:5]",
  98. },
  99. },
  100. },
  101. devServer: {
  102. proxy: {
  103. "/api": {
  104. target: url, // 服务端地址
  105. pathRewrite: {
  106. "^/api": "",
  107. },
  108. changeOrigin: true,
  109. },
  110. },
  111. },
  112. },
  113. };
  114. if (process.env.NODE_ENV === "development") {
  115. return merge({}, config, devConfig);
  116. }
  117. return merge({}, config, prodConfig);
  118. });