vite.config.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import { ViteEjsPlugin } from 'vite-plugin-ejs'
  5. import path from 'path'
  6. // unplugin-vue-components 会解析模板并自动注册对应的组件,使用函数组件时,unplugin-vue-components 无法自动引入对应的样式,因此需要手动引入样式
  7. import Components from 'unplugin-vue-components/vite'
  8. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  9. // https://vitejs.dev/config/
  10. // @ts-ignore
  11. export default ({ mode }) =>
  12. defineConfig({
  13. plugins: [
  14. vue(),
  15. vueJsx(),
  16. Components({
  17. resolvers: [ElementPlusResolver()]
  18. }),
  19. ViteEjsPlugin(() => {
  20. return {
  21. // BASE_URL: loadEnv(mode, process.cwd()).VITE_APP_BASE_DOMIAN,
  22. TITLE: '上海市CIM平台'
  23. // JS_MOUDLES: ['/websdk/latest/cimcube/cimcube.js'],
  24. // CSS_MOUDLES: [
  25. // '/websdk/latest/cimcube/Widgets/widgets.css',
  26. // '/websdk/latest/Resource/css/Widgets.css'
  27. // ]
  28. }
  29. }),
  30. ],
  31. base: 'a',
  32. resolve: {
  33. alias: {
  34. '@': path.resolve(__dirname, './src'),
  35. '@assets': path.resolve(__dirname, './src/assets'),
  36. '@common': path.resolve(__dirname, './src/common'),
  37. '@utils': path.resolve(__dirname, './src/utils'),
  38. '@components': path.resolve(__dirname, './src/components'),
  39. '@views': path.resolve(__dirname, './src/views'),
  40. '@styles': path.resolve(__dirname, './src/styles')
  41. }
  42. },
  43. // 服务配置
  44. server: {
  45. host: '0.0.0.0',
  46. port: 4450, // 类型: number 指定服务器端口;
  47. open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
  48. proxy: {
  49. '/api': {
  50. // target: `https://www${envStr}.bimface.com/api`,
  51. target: loadEnv(mode, process.cwd()).VITE_APP_BASE_DOMIAN,
  52. changeOrigin: true,
  53. rewrite: (apiPath) => apiPath.replace(/^\/api/, ''),
  54. cookieDomainRewrite: 'localhost'
  55. },
  56. '/bf': {
  57. // target: `https://www${envStr}.bimface.com/api`,
  58. target: loadEnv(mode, process.cwd()).VITE_APP_BASE_DOMIAN,
  59. changeOrigin: true,
  60. //rewrite: (apiPath) => apiPath.replace(/^\/bf/, ''),
  61. cookieDomainRewrite: 'localhost'
  62. }
  63. }
  64. },
  65. // css 处理
  66. css: {
  67. preprocessorOptions: {
  68. scss: {
  69. /* .scss全局预定义变量,引入多个文件 以;(分号分割)*/
  70. additionalData: '@import "./src/styles/elementPlus/var.scss";'
  71. }
  72. }
  73. },
  74. // 生产环境
  75. build: {
  76. minify: 'terser',
  77. target: 'es2015',
  78. // 指定输出路径
  79. assetsDir: './',
  80. // 指定输出文件路径
  81. outDir: 'dist',
  82. // 代码压缩配置
  83. terserOptions: {
  84. // 生产环境移除console
  85. compress: {
  86. drop_console: true,
  87. drop_debugger: true
  88. }
  89. },
  90. chunkSizeWarningLimit: 2000
  91. },
  92. })