index.js 3.4KB

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