You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

1 month ago
1 month ago
  1. // import { defineConfig } from 'vite'
  2. // import vue from '@vitejs/plugin-vue'
  3. // import path from 'path'
  4. // // https://vite.dev/config/
  5. // // export default defineConfig({
  6. // // plugins: [vue()],
  7. // // })
  8. // export default defineConfig({
  9. // plugins: [
  10. // vue(),
  11. // ],
  12. // resolve: {
  13. // alias: {
  14. // '@': path.resolve(process.cwd(), 'src')
  15. // }
  16. // },
  17. // server: {
  18. // proxy: {
  19. // '/Api': {
  20. // target: 'https://dbqb.nfdxy.net/devLotApi',
  21. // // target: 'http://localhost:8080',
  22. // changeOrigin: true,
  23. // rewrite: (path) => path.replace(/^\/Api/, '')
  24. // }
  25. // }
  26. // }
  27. // })
  28. import { defineConfig, loadEnv } from "vite";
  29. import pkg from "./package.json"; // 新增包信息导入
  30. import dayjs from "dayjs"; // 新增时间库导入
  31. import { fileURLToPath, URL } from "url"; // 新增路径处理模块
  32. import { wrapperEnv } from "./build/utils";
  33. import { createVitePlugins } from "./build/vite/plugin";
  34. import { createProxy } from "./build/vite/proxy";
  35. import { createBuild } from "./build/vite/build";
  36. const { dependencies, devDependencies, name, version } = pkg;
  37. // 应用信息
  38. const __APP_INFO__ = {
  39. pkg: { dependencies, devDependencies, name, version },
  40. lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
  41. };
  42. // https://vite.dev/config/
  43. export default defineConfig(({ command, mode }) => {
  44. // console.log('command', command)
  45. const root = process.cwd(); // 当前工作目录
  46. const isBuild = command === "build"; // 是否是构建 serve
  47. const env = loadEnv(mode, root); // 加载env环境
  48. // The boolean type read by loadEnv is a string. This function can be converted to boolean type
  49. const viteEnv = wrapperEnv(env);
  50. // console.log('viteEnv', viteEnv)
  51. const { VITE_PUBLIC_PATH, VITE_OUTPUT_DIR } = viteEnv;
  52. return {
  53. base: VITE_PUBLIC_PATH,
  54. root,
  55. plugins: createVitePlugins(viteEnv, isBuild),
  56. resolve: {
  57. alias: {
  58. "@": fileURLToPath(new URL("./src", import.meta.url)),
  59. },
  60. },
  61. css: {
  62. preprocessorOptions: {
  63. scss: {
  64. charset: false, // 避免出现: build时的 @charset 必须在第一行的警告
  65. },
  66. },
  67. },
  68. server: {
  69. host: true,
  70. proxy: createProxy(),
  71. },
  72. build: createBuild(viteEnv),
  73. define: {
  74. __APP_INFO__: JSON.stringify(__APP_INFO__),
  75. }
  76. };
  77. });