index.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { defineConfig } from "@tarojs/cli";
  2. const path = require("path");
  3. import devConfig from "./dev";
  4. import prodConfig from "./prod";
  5. export default defineConfig(async (merge, { command, mode }) => {
  6. const config = {
  7. projectName: "civilized-miniapp",
  8. date: "2024-03-21",
  9. designWidth: 750,
  10. deviceRatio: {
  11. 640: 2.34 / 2,
  12. 750: 1,
  13. 828: 1.81 / 2,
  14. },
  15. sourceRoot: "src",
  16. outputRoot: "dist",
  17. plugins: [],
  18. defineConstants: {},
  19. copy: {
  20. patterns: [{ from: "src/assets/tabbar/", to: "dist/assets/tabbar/" }],
  21. options: {},
  22. },
  23. framework: "react",
  24. compiler: "webpack4",
  25. alias: {
  26. "@": path.resolve(__dirname, "..", "src"),
  27. },
  28. mini: {
  29. postcss: {
  30. pxtransform: {
  31. enable: true,
  32. config: {},
  33. },
  34. url: {
  35. enable: true,
  36. config: {
  37. limit: 1024, // 设定转换尺寸上限
  38. },
  39. },
  40. cssModules: {
  41. enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
  42. config: {
  43. namingPattern: "module", // 转换模式,取值为 global/module
  44. generateScopedName: "[name]__[local]___[hash:base64:5]",
  45. },
  46. },
  47. },
  48. },
  49. h5: {
  50. publicPath: "/",
  51. staticDirectory: "static",
  52. outputDir: 'dist',
  53. router : {
  54. mode : "hash",
  55. // base : "./"
  56. },
  57. // output: {
  58. // filename: "js/[name].[hash:8].js",
  59. // chunkFilename: "js/[name].[chunkhash:8].js",
  60. // },
  61. miniCssExtractPluginOption: {
  62. ignoreOrder: true,
  63. filename: "css/[name].[hash].css",
  64. chunkFilename: "css/[name].[chunkhash].css",
  65. },
  66. postcss: {
  67. autoprefixer: {
  68. enable: true,
  69. config: {},
  70. },
  71. cssModules: {
  72. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  73. config: {
  74. namingPattern: "module", // 转换模式,取值为 global/module
  75. generateScopedName: "[name]__[local]___[hash:base64:5]",
  76. },
  77. },
  78. },
  79. // devServer: {
  80. // host: "0.0.0.0",
  81. // // port: ,
  82. // proxy: {
  83. // "/api": {
  84. // target: "http://127.0.0.1:9087", // 服务端地址
  85. // pathRewrite: {
  86. // '/api': ''
  87. // },
  88. // changeOrigin: true,
  89. // },
  90. // },
  91. // },
  92. },
  93. };
  94. if (process.env.NODE_ENV === "development") {
  95. return merge({}, config, devConfig);
  96. }
  97. return merge({}, config, prodConfig);
  98. });