vite.config.ts 2.4 KB

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