index.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { defineConfig } from "@tarojs/cli";
  2. import devConfig from "./dev";
  3. import prodConfig from "./prod";
  4. // eslint-disable-next-line import/no-commonjs
  5. const path = require("path");
  6. const url = "http://localhost:9087";
  7. const url2 = "https://apis.map.qq.com";
  8. export default defineConfig(async (merge, { command, mode }) => {
  9. const config = {
  10. projectName: "civilized-miniapp",
  11. date: "2024-03-21",
  12. designWidth(input) {
  13. // console.log("---->", input?.file);
  14. // if (input?.file.replace(/\\+/g, '/').indexOf('@antmjs/vantui') > -1) {
  15. // return 750
  16. // }
  17. return 750;
  18. },
  19. deviceRatio: {
  20. 640: 2.34 / 2,
  21. 750: 1,
  22. 828: 1.81 / 2,
  23. 375: 2 / 1,
  24. },
  25. // jsMinimizer: 'terser',
  26. // terser: {
  27. // enable: false,
  28. // },
  29. sourceRoot: "src",
  30. outputRoot: "dist",
  31. plugins: [],
  32. defineConstants: {},
  33. copy: {
  34. patterns: [
  35. { from: "src/assets/tabbar/", to: "dist/assets/tabbar/" },
  36. { from: "src/assets/js/", to: "dist/assets/js/" },
  37. ],
  38. options: {},
  39. },
  40. framework: "react",
  41. compiler: "webpack4",
  42. alias: {
  43. "@": path.resolve(__dirname, "..", "src"),
  44. },
  45. // mini: {
  46. // postcss: {
  47. // pxtransform: {
  48. // enable: true,
  49. // config: {},
  50. // },
  51. // url: {
  52. // enable: true,
  53. // config: {
  54. // limit: 1024, // 设定转换尺寸上限
  55. // },
  56. // },
  57. // cssModules: {
  58. // enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  59. // config: {
  60. // namingPattern: "module", // 转换模式,取值为 global/module
  61. // generateScopedName: "[name]__[local]___[hash:base64:5]",
  62. // },
  63. // },
  64. // },
  65. // },
  66. h5: {
  67. publicPath: "/h5",
  68. // staticDirectory: "static",
  69. // outputDir: "dist",
  70. // uglify:false,
  71. router: {
  72. mode: "hash",
  73. basename:""
  74. },
  75. esnextModules: ["@antmjs"],
  76. postcss: {
  77. autoprefixer: {
  78. enable: true,
  79. config: {},
  80. },
  81. pxtransform: {
  82. enable: true,
  83. config: {
  84. },
  85. },
  86. cssModules: {
  87. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  88. config: {
  89. namingPattern: "module", // 转换模式,取值为 global/module,下文详细说明
  90. generateScopedName: "[name]__[local]___[hash:base64:5]",
  91. },
  92. },
  93. },
  94. devServer: {
  95. proxy: {
  96. "/api2": {
  97. target: url2, // 服务端地址
  98. changeOrigin: true,
  99. pathRewrite: {
  100. "^/api2": "",
  101. },
  102. },
  103. "/api": {
  104. target: url, // 服务端地址
  105. changeOrigin: true,
  106. },
  107. },
  108. },
  109. webpackChain(chain, webpack) {
  110. chain.merge({
  111. mode: "development",
  112. })
  113. },
  114. },
  115. };
  116. if (process.env.NODE_ENV === "development") {
  117. return merge({}, config, devConfig);
  118. }
  119. return merge({}, config, prodConfig);
  120. });