vite.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import path from 'path'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. // import legacy from '@vitejs/plugin-legacy'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import Icons from 'unplugin-icons/vite'
  9. import deletePlugin from 'rollup-plugin-delete'
  10. // import basicSsl from '@vitejs/plugin-basic-ssl'
  11. import Unocss from 'unocss/vite'
  12. import { PrimeVueResolver } from '@primevue/auto-import-resolver'
  13. // https://vitejs.dev/config/
  14. export default ({ mode, command }) => {
  15. // const env = loadEnv(mode, process.cwd())
  16. return defineConfig({
  17. base: '/mr/foreground/',
  18. build: {
  19. outDir: 'foreground',
  20. sourcemap: false,
  21. emptyOutDir: true,
  22. chunkSizeWarningLimit: 1024,
  23. rollupOptions: {
  24. output: {
  25. chunkFileNames: 'js/[hash].js',
  26. entryFileNames: 'js/[hash].js',
  27. assetFileNames: (assetsFile) => {
  28. if (/\.(vue|scss)$/i.test(assetsFile.name)) {
  29. return 'del/[name]-[hash].[ext]'
  30. } else {
  31. return 'static/[hash].[ext]'
  32. }
  33. }
  34. }
  35. },
  36. minify: 'terser' // 必须使用 terser 才能支持 legacy 插件的混淆
  37. },
  38. plugins: [
  39. vue(),
  40. // legacy({
  41. // targets: ['> 0.2%', 'not dead'],
  42. // polyfills: ['es.promise.finally', 'es/map', 'es/set'],
  43. // // 自动引入必要的 polyfill
  44. // additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  45. // // 如果使用了特殊的 ES 语法,可以在这里强制 polyfill
  46. // modernPolyfills: true
  47. // }),
  48. vueJsx(),
  49. // basicSsl(),
  50. Unocss({}),
  51. AutoImport({
  52. imports: [
  53. 'vue',
  54. 'vue-router',
  55. 'pinia',
  56. '@vueuse/core',
  57. {
  58. '@/api': ['useRequest']
  59. },
  60. {
  61. '@/locales': ['useI18n', 'locale']
  62. }
  63. ],
  64. eslintrc: {
  65. enabled: false, // Default `false`
  66. filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
  67. globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
  68. }
  69. }),
  70. Components({
  71. dirs: ['src/components'],
  72. dts: false,
  73. resolvers: [PrimeVueResolver()],
  74. include: [/\.vue$/, /\.vue\?vue/, /\.jsx$/]
  75. }),
  76. Icons({
  77. compiler: 'vue3'
  78. }),
  79. deletePlugin({
  80. targets: ['foreground/del'],
  81. hook: 'writeBundle'
  82. })
  83. ],
  84. resolve: {
  85. alias: {
  86. '@': path.resolve(__dirname, 'src'),
  87. assets: path.resolve(__dirname, 'src/assets'),
  88. util: path.resolve(__dirname, 'src/util'),
  89. views: path.resolve(__dirname, 'src/views'),
  90. layout: path.resolve(__dirname, 'src/layout'),
  91. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  92. }
  93. },
  94. optimizeDeps: {
  95. exclude: ['omnimatrix-video-player']
  96. },
  97. preprocessorOptions: {
  98. scss: {
  99. // additionalData: `@import "@/assets/base.scss";`
  100. }
  101. },
  102. define: {
  103. __DEV__: mode === 'development',
  104. __TEST__: mode === 'test'
  105. }
  106. // server:{
  107. // proxy:{
  108. // '/alarm':{
  109. // target: 'https://127.0.0.1',
  110. // changeOrigin: true,
  111. // rewrite: (path) => path.replace(/^api/, ''),
  112. // }
  113. // }
  114. // }
  115. })
  116. }