vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import type { UserConfig, ConfigEnv } from 'vite'
  2. import { loadEnv } from 'vite'
  3. import { resolve } from 'path'
  4. import { wrapperEnv } from './build/utils'
  5. import { createVitePlugins } from './build/vite/plugin'
  6. import { OUTPUT_DIR } from './build/constant'
  7. // import { createProxy } from './build/vite/proxy'
  8. import pkg from './package.json'
  9. import { format } from 'date-fns'
  10. const { dependencies, devDependencies, name, version } = pkg
  11. const __APP_INFO__ = {
  12. pkg: { dependencies, devDependencies, name, version },
  13. lastBuildTime: format(new Date(), 'yyyy-MM-dd HH:mm:ss')
  14. }
  15. function pathResolve(dir: string) {
  16. return resolve(process.cwd(), '.', dir)
  17. }
  18. // const proxyUrl = 'https://dev.lexiaoya.cn/'
  19. // const proxyUrl = 'http://127.0.0.1:7293/'
  20. const proxyUrl = 'https://dev.resource.colexiu.com'
  21. export default ({ command, mode }: ConfigEnv): UserConfig => {
  22. const root = process.cwd()
  23. const env = loadEnv(mode, root)
  24. const viteEnv = wrapperEnv(env)
  25. const { VITE_PUBLIC_PATH, VITE_DROP_CONSOLE, VITE_PORT, VITE_GLOB_PROD_MOCK } = viteEnv
  26. const prodMock = VITE_GLOB_PROD_MOCK
  27. const isBuild = command === 'build'
  28. return {
  29. base: VITE_PUBLIC_PATH,
  30. esbuild: {},
  31. // resolve: {
  32. // alias: [
  33. // {
  34. // find: /\/#\//,
  35. // replacement: pathResolve('types') + '/'
  36. // },
  37. // {
  38. // find: '@',
  39. // replacement: pathResolve('src') + '/'
  40. // }
  41. // ],
  42. // dedupe: ['vue']
  43. // },
  44. resolve: {
  45. alias: {
  46. '@': pathResolve('src') + '/',
  47. '@components': pathResolve('src/components') + '/',
  48. '@views': pathResolve('src/views') + '/'
  49. }
  50. },
  51. plugins: createVitePlugins(viteEnv, isBuild, prodMock),
  52. define: {
  53. __APP_INFO__: JSON.stringify(__APP_INFO__)
  54. },
  55. css: {
  56. preprocessorOptions: {
  57. less: {
  58. modifyVars: {},
  59. javascriptEnabled: true,
  60. additionalData: `@import "src/styles/var.less";`
  61. }
  62. }
  63. },
  64. server: {
  65. host: true,
  66. port: VITE_PORT,
  67. proxy: {
  68. '/cbs-app': {
  69. target: proxyUrl,
  70. changeOrigin: true
  71. }
  72. }
  73. },
  74. optimizeDeps: {
  75. include: [],
  76. exclude: ['vue-demi']
  77. },
  78. build: {
  79. target: 'es2015',
  80. cssTarget: 'chrome80',
  81. outDir: OUTPUT_DIR,
  82. chunkSizeWarningLimit: 2000
  83. }
  84. }
  85. }