vite.config.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import eslint from 'vite-plugin-eslint'
  5. import viteCompression from 'vite-plugin-compression'
  6. import { resolve } from 'path'
  7. // https://vitejs.dev/config/
  8. export default ({ mode }) => {
  9. const env = loadEnv(mode, process.cwd())
  10. return defineConfig({
  11. base: './',
  12. resolve: {
  13. alias: {
  14. /*
  15. 路径别名
  16. 若为文件系统路径必须是绝对路径的形式,否则将以别名原样呈现,不会解析为文件系统路径路径
  17. */
  18. '@': resolve(__dirname, './src')
  19. }
  20. },
  21. plugins: [
  22. vue(), viteCompression(),
  23. eslint({ fix: true, include: [ '**/*.ts', '**/*.vue' ] })
  24. ],
  25. server: {
  26. host: '0.0.0.0',
  27. port: 6888,
  28. open: true,
  29. strictPort: false,
  30. // proxy: {
  31. // '/api': {
  32. // target: env.VITE_PROXY_URL,
  33. // changeOrigin: true,
  34. // rewrite: (path) => path.replace(/^\/api/, ''),
  35. // secure: false,
  36. // headers: {
  37. // Referer: 'https://example.com'
  38. // }
  39. // }
  40. // }
  41. },
  42. esbuild: {
  43. drop: mode === 'development' ? [ 'debugger' ] : [ 'debugger', 'console' ] // build 移除打印
  44. },
  45. build: {
  46. rollupOptions: {
  47. input: {
  48. index: resolve(__dirname, 'index.html')
  49. },
  50. output: { // 静态资源分类打包
  51. chunkFileNames: 'js/[hash].js',
  52. entryFileNames: 'js/[hash].js',
  53. assetFileNames: 'assets/[ext]/[hash].[ext]',
  54. // 拆分node_modules包
  55. manualChunks: (id: any) => {
  56. if (id.includes('node_modules')) {
  57. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  58. }
  59. return ''
  60. }
  61. }
  62. }
  63. },
  64. define: {
  65. __VUE_OPTIONS_API__: false
  66. }
  67. })
  68. }