vite.config.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import vue from "@vitejs/plugin-vue";
  2. import { resolve } from "path";
  3. import { defineConfig, loadEnv, UserConfig, UserConfigExport } from "vite";
  4. import { createHtmlPlugin } from "vite-plugin-html";
  5. import tsconfigPaths from "vite-tsconfig-paths";
  6. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  7. export default (config: UserConfig): UserConfigExport => {
  8. const mode = config.mode as string;
  9. return defineConfig({
  10. base: "./",
  11. plugins: [
  12. vue(),
  13. createHtmlPlugin({
  14. minify: true,
  15. inject: {
  16. data: {
  17. apiURL: loadEnv(mode, process.cwd()).VITE_APP_API,
  18. title: ""
  19. },
  20. tags: [
  21. {
  22. injectTo: 'body-prepend',
  23. tag: 'div',
  24. attrs: {
  25. id: 'tag'
  26. }
  27. }
  28. ]
  29. }
  30. }),
  31. tsconfigPaths(),
  32. createSvgIconsPlugin({
  33. iconDirs: [resolve(__dirname, "src/assets/icons/svg")],
  34. symbolId: "icon-[dir]-[name]"
  35. })
  36. ],
  37. build: {
  38. chunkSizeWarningLimit: 1024,
  39. commonjsOptions: {
  40. include: /node_modules|lib/
  41. },
  42. rollupOptions: {
  43. output: {
  44. manualChunks: {
  45. quill: ["quill"],
  46. lodash: ["lodash"],
  47. vlib: ["vue", "vue-router", "element-plus"]
  48. }
  49. }
  50. }
  51. },
  52. resolve: {
  53. alias: {
  54. // 配置别名
  55. "@": resolve(__dirname, "./src")
  56. }
  57. },
  58. server: {
  59. open: false, // 自动启动浏览器
  60. host: "0.0.0.0", // localhost
  61. port: 8001, // 端口号
  62. hmr: { overlay: false }
  63. }
  64. });
  65. };