vite.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: [ vue(), viteCompression(), eslint({ fix: true, include: [ '**/*.ts', '**/*.vue' ] }) ],
  22. server: {
  23. host: '0.0.0.0',
  24. port: 6888,
  25. open: true,
  26. strictPort: false,
  27. https: false,
  28. // proxy: {
  29. // '/api': {
  30. // target: env.VITE_PROXY_URL,
  31. // changeOrigin: true,
  32. // rewrite: (path) => path.replace(/^\/api/, ''),
  33. // secure: false,
  34. // headers: {
  35. // Referer: 'https://example.com'
  36. // }
  37. // }
  38. // }
  39. },
  40. esbuild: {
  41. drop: [ 'console', 'debugger' ] // build 移除打印
  42. },
  43. build: {
  44. rollupOptions: {
  45. input: {
  46. index: resolve(__dirname, 'index.html')
  47. },
  48. output: { // 静态资源分类打包
  49. chunkFileNames: 'js/[hash].js',
  50. entryFileNames: 'js/[hash].js',
  51. assetFileNames: 'assets/[ext]/[hash].[ext]',
  52. // 拆分node_modules包
  53. manualChunks: (id: any) => {
  54. if (id.includes('node_modules')) {
  55. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  56. }
  57. return ''
  58. }
  59. }
  60. }
  61. },
  62. define: {
  63. __VUE_OPTIONS_API__: false
  64. }
  65. })
  66. }