vite.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "node:path";
  4. import { createHtmlPlugin } from 'vite-plugin-html';
  5. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  6. import { version } from './package.json'
  7. // https://vite.dev/config/
  8. export default ({ mode }: any) => {
  9. const env = loadEnv(mode, process.cwd())
  10. let proxy
  11. if (mode === 'development') {
  12. const getProxy = (prev: string, api: string) => ({
  13. target: api,
  14. changeOrigin: true,
  15. rewrite: (path: any) => path.replace(prev, '')
  16. })
  17. proxy = {
  18. ['/meshOSS']: getProxy('/meshOSS', 'https://4dkk.4dage.com/'),
  19. ['/meshAPI']: getProxy('/meshAPI', 'https://test.4dkankan.com/'),
  20. ['/cloudAPI']: getProxy('/cloudAPI', 'https://uat-laser.4dkankan.com/'),
  21. ['/fuseAPI']: getProxy('/fuseAPI', 'https://test-mix3d.4dkankan.com/'),
  22. }
  23. }
  24. return defineConfig({
  25. resolve: {
  26. alias: {
  27. "@/": `${path.resolve(__dirname, "src")}/`,
  28. },
  29. },
  30. css: {
  31. preprocessorOptions: {
  32. scss: {
  33. quietDeps: true,
  34. additionalData: `
  35. @forward 'element-plus/theme-chalk/src/common/var' with (
  36. $colors: (
  37. 'primary': (
  38. 'base': ${env.VITE_PRIMARY},
  39. ),
  40. ),
  41. );
  42. `,
  43. },
  44. },
  45. },
  46. server: {
  47. port: 9010,
  48. open: true,
  49. host: "0.0.0.0",
  50. proxy: proxy,
  51. },
  52. plugins: [
  53. createSvgIconsPlugin({
  54. iconDirs: [path.resolve(process.cwd(), 'public/icons')],
  55. symbolId: 'icon-[dir]-[name]'
  56. }),
  57. createHtmlPlugin({
  58. template: 'index.html',
  59. entry: path.resolve('src', env.VITE_ENTRY),
  60. inject: {
  61. data: {
  62. title: env.VITE_TITLE,
  63. },
  64. }
  65. }),
  66. vue()
  67. ],
  68. define: {
  69. __VERSION__: JSON.stringify(version)
  70. }
  71. });
  72. };