vite.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { resolve } from "path";
  4. import envConfig from "./env.config.js";
  5. import scssVariables from "./src/styles/variables.scss.js";
  6. const scssAdditionalData = [
  7. '@use "sass:color" as color;',
  8. ...Object.keys(scssVariables).map(
  9. (k) => `$${k.replace("_", "-")}: ${scssVariables[k]};`
  10. ),
  11. ].join("\n");
  12. export default defineConfig(({ mode }) => {
  13. const currentEnv = envConfig[mode] || envConfig.development;
  14. return {
  15. plugins: [vue()],
  16. resolve: {
  17. alias: {
  18. "@": resolve(__dirname, "src"),
  19. },
  20. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  21. },
  22. css: {
  23. preprocessorOptions: {
  24. scss: {
  25. additionalData: scssAdditionalData,
  26. silenceDeprecations: ["legacy-js-api"],
  27. },
  28. },
  29. },
  30. server: {
  31. host: "127.0.0.1",
  32. port: 8082,
  33. open: false,
  34. proxy: {
  35. "/ws": {
  36. target: "https://apis.map.qq.com",
  37. changeOrigin: true,
  38. ws: false,
  39. },
  40. "/v3/elevation": {
  41. target: "https://restapi.amap.com",
  42. changeOrigin: true,
  43. ws: false,
  44. },
  45. },
  46. },
  47. build: {
  48. target: "es2020",
  49. outDir: "dist",
  50. assetsDir: "assets",
  51. sourcemap: false,
  52. minify: "esbuild",
  53. rollupOptions: {
  54. output: {
  55. chunkFileNames: "js/[name]-[hash].js",
  56. entryFileNames: "js/[name]-[hash].js",
  57. assetFileNames: "[ext]/[name]-[hash].[ext]",
  58. manualChunks: {
  59. vue: ["vue", "vue-router"],
  60. elementPlus: ["element-plus"],
  61. ol: ["ol"],
  62. },
  63. },
  64. },
  65. },
  66. define: {
  67. VE_ENV: {
  68. MODE: JSON.stringify(currentEnv.NODE_ENV),
  69. SERVER: JSON.stringify(currentEnv.SERVER),
  70. PYSERVER: JSON.stringify(currentEnv.PYSERVER),
  71. NEW_SERVER: JSON.stringify(currentEnv.NEW_SERVER),
  72. },
  73. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false",
  74. },
  75. optimizeDeps: {
  76. include: ["vue", "vue-router", "element-plus", "axios", "dayjs", "ol"],
  77. },
  78. };
  79. });