index.js 3.0KB

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