index.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. publicPath: "/",
  53. staticDirectory: "static",
  54. outputDir: "dist",
  55. router: {
  56. mode: "hash",
  57. },
  58. esnextModules: ["@antmjs/vantui"],
  59. miniCssExtractPluginOption: {
  60. ignoreOrder: true,
  61. filename: "css/[name].[hash].css",
  62. chunkFilename: "css/[id].css",
  63. },
  64. postcss: {
  65. pxtransform: {
  66. enable: true,
  67. config: {
  68. // 设置rpx转换为目标单位为rem
  69. unitToRem: true,
  70. // 设计稿宽度与 rem 基准值,默认设计稿宽度为 750,即 1rem = 75px
  71. designWidth: 750,
  72. // 可选,选择器黑名单
  73. selectorBlackList: [],
  74. // // 可选,替换rpx为其他单位后缀,例如 'px' 或 'rem'
  75. propList: ["*"],
  76. // 可选,媒体查询中是否禁用转换
  77. mediaQuery: false,
  78. // 可选,是否转换页面根节点字体大小,如body: font-size: 16px
  79. minPixelValue: 0,
  80. },
  81. },
  82. cssModules: {
  83. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  84. config: {
  85. namingPattern: "module", // 转换模式,取值为 global/module,下文详细说明
  86. generateScopedName: "[name]__[local]___[hash:base64:5]",
  87. },
  88. },
  89. },
  90. devServer: {
  91. proxy: {
  92. "/api": {
  93. target: url, // 服务端地址
  94. pathRewrite: {
  95. "^/api": "",
  96. },
  97. changeOrigin: true,
  98. },
  99. },
  100. },
  101. },
  102. };
  103. if (process.env.NODE_ENV === "development") {
  104. return merge({}, config, devConfig);
  105. }
  106. return merge({}, config, prodConfig);
  107. });