vite.config.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import legacy from '@vitejs/plugin-legacy'
  4. import * as fs from 'node:fs'
  5. import * as path from 'node:path'
  6. export default defineConfig(({ mode }) => {
  7. return {
  8. plugins: [vue(),
  9. legacy({
  10. targets: ['> 0.1%', 'not dead','chrome <= 66'],
  11. additionalLegacyPolyfills: [
  12. 'core-js/stable',
  13. 'regenerator-runtime/runtime',
  14. ],
  15. }),
  16. {
  17. name: 'setting-txt',
  18. generateBundle() {
  19. const filePath = path.resolve(__dirname, 'src/static/setting.txt'); // 请确保路径正确
  20. if (fs.existsSync(filePath)) {
  21. let content = fs.readFileSync(filePath, 'utf-8');
  22. let count = parseInt(content, 10) || 0
  23. count ++
  24. fs.writeFileSync(filePath, count.toString(), 'utf-8');
  25. } else {
  26. fs.writeFileSync(filePath, '1', 'utf-8');
  27. }
  28. }
  29. }
  30. ],
  31. server: {
  32. host: '0.0.0.0', // 允许通过局域网访问
  33. port: 5173, // 修改为你需要的端口号
  34. },
  35. resolve: {
  36. alias: {
  37. '@': '/src'
  38. }
  39. },
  40. optimizeDeps: {
  41. include: ['vue','eruda']
  42. },
  43. base:'./',
  44. build: {
  45. sourcemap: mode === 'development'
  46. },
  47. }
  48. })