index.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. "@antmjs/vantui/es/field/index": path.resolve(__dirname, "..", "node_modules/@antmjs/vantui/es/field/index.js"),
  45. "@antmjs/vantui/es/field/index.css": path.resolve(__dirname, "..", "node_modules/@antmjs/vantui/es/field/index.less"),
  46. },
  47. // mini: {
  48. // postcss: {
  49. // pxtransform: {
  50. // enable: true,
  51. // config: {},
  52. // },
  53. // url: {
  54. // enable: true,
  55. // config: {
  56. // limit: 1024, // 设定转换尺寸上限
  57. // },
  58. // },
  59. // cssModules: {
  60. // enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  61. // config: {
  62. // namingPattern: "module", // 转换模式,取值为 global/module
  63. // generateScopedName: "[name]__[local]___[hash:base64:5]",
  64. // },
  65. // },
  66. // },
  67. // },
  68. h5: {
  69. publicPath: "/h5",
  70. // staticDirectory: "static",
  71. // outputDir: "dist",
  72. // uglify:false,
  73. router: {
  74. mode: "hash",
  75. basename:""
  76. },
  77. esnextModules: ["@antmjs"],
  78. postcss: {
  79. autoprefixer: {
  80. enable: true,
  81. config: {},
  82. },
  83. pxtransform: {
  84. enable: true,
  85. config: {
  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. webpackChain(chain, webpack) {
  112. chain.merge({
  113. mode: "development",
  114. })
  115. },
  116. },
  117. };
  118. if (process.env.NODE_ENV === "development") {
  119. return merge({}, config, devConfig);
  120. }
  121. return merge({}, config, prodConfig);
  122. });