vite.config.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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://resource.colexiu.com/'
  21. const proxyUrl = 'https://dev.resource.colexiu.com/'
  22. // https://test.resource.colexiu.com/
  23. export default ({ command, mode }: ConfigEnv): UserConfig => {
  24. const root = process.cwd()
  25. const env = loadEnv(mode, root)
  26. const viteEnv = wrapperEnv(env)
  27. const { VITE_PUBLIC_PATH, VITE_DROP_CONSOLE, VITE_PORT, VITE_GLOB_PROD_MOCK } = viteEnv
  28. const prodMock = VITE_GLOB_PROD_MOCK
  29. const isBuild = command === 'build'
  30. return {
  31. base: VITE_PUBLIC_PATH,
  32. esbuild: {},
  33. // resolve: {
  34. // alias: [
  35. // {
  36. // find: /\/#\//,
  37. // replacement: pathResolve('types') + '/'
  38. // },
  39. // {
  40. // find: '@',
  41. // replacement: pathResolve('src') + '/'
  42. // }
  43. // ],
  44. // dedupe: ['vue']
  45. // },
  46. resolve: {
  47. alias: {
  48. '@': pathResolve('src') + '/',
  49. '@components': pathResolve('src/components') + '/',
  50. '@views': pathResolve('src/views') + '/'
  51. }
  52. },
  53. plugins: createVitePlugins(viteEnv, isBuild, prodMock),
  54. define: {
  55. __APP_INFO__: JSON.stringify(__APP_INFO__)
  56. },
  57. css: {
  58. preprocessorOptions: {
  59. less: {
  60. modifyVars: {},
  61. javascriptEnabled: true,
  62. additionalData: `@import "src/styles/var.less";`
  63. }
  64. }
  65. },
  66. server: {
  67. host: true,
  68. port: VITE_PORT,
  69. proxy: {
  70. '/cbs-app': {
  71. target: proxyUrl,
  72. changeOrigin: true
  73. }
  74. }
  75. },
  76. optimizeDeps: {
  77. include: [],
  78. exclude: ['vue-demi']
  79. },
  80. build: {
  81. target: 'es2015',
  82. cssTarget: 'chrome80',
  83. outDir: OUTPUT_DIR,
  84. chunkSizeWarningLimit: 2000
  85. }
  86. }
  87. }