vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import vue from '@vitejs/plugin-vue'
  2. import path from 'path'
  3. import { ConfigEnv, defineConfig, UserConfigExport } from 'vite'
  4. import { viteVConsole } from 'vite-plugin-vconsole'
  5. export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
  6. base: '/',
  7. css: {
  8. preprocessorOptions: {
  9. scss: {
  10. additionalData: '@import "./src/styles/variables";'
  11. },
  12. }
  13. },
  14. resolve: {
  15. alias: [
  16. {
  17. find: '/@',
  18. replacement: path.resolve(__dirname, './src'),
  19. }
  20. ]
  21. },
  22. server: {
  23. // 监听所有地址
  24. host: '0.0.0.0',
  25. // 自定义端口号
  26. port: 8080,
  27. // 自动打开浏览器
  28. open: true,
  29. // 开启热更新
  30. hmr: true,
  31. // 若端口被占用,自动尝试下一个可用端口
  32. strictPort: false,
  33. // 代理规则
  34. proxy: {
  35. '/api': {
  36. // 开启跨域
  37. changeOrigin: true,
  38. // 转发地址
  39. target: 'http://192.168.3.42:6789',
  40. // 路径重写
  41. rewrite: (path) => path.replace(/^\/api/, ''),
  42. }
  43. }
  44. },
  45. build: {
  46. target: ['es2015'], // 最低支持 es2015
  47. sourcemap: false,// 构建后不生成源代码
  48. write: true,// 构建的文件写入磁盘
  49. chunkSizeWarningLimit: 10240,// 触发警告的chunk大小10M
  50. },
  51. plugins: [
  52. vue(),
  53. viteVConsole({
  54. entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
  55. localEnabled: command === 'serve', // serve开发环境下
  56. // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
  57. config: { // vconsole 配置项
  58. maxLogNumber: 1000,
  59. theme: 'light'
  60. }
  61. }),
  62. ],
  63. })