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