vite.config.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { defineConfig, loadEnv } from 'vite'
  2. import legacy from '@vitejs/plugin-legacy'
  3. import { createVuePlugin } from 'vite-plugin-vue2'
  4. import viteCompression from 'vite-plugin-compression'
  5. import path from 'path'
  6. // import eslintPlugin from 'vite-plugin-eslint'
  7. const HOST = '0.0.0.0'
  8. const REPLACEMENT = `${path.resolve(__dirname, './src')}/`
  9. export default ({ mode }) => {
  10. const env = loadEnv(mode, process.cwd())
  11. return defineConfig({
  12. base: './',
  13. server: {
  14. host: HOST,
  15. port: process.env.PORT
  16. },
  17. define: {
  18. 'process.env': { ...env }
  19. },
  20. resolve: {
  21. alias: [
  22. {
  23. find: '@/',
  24. replacement: REPLACEMENT
  25. },
  26. {
  27. find: 'src/',
  28. replacement: REPLACEMENT
  29. }
  30. ],
  31. extensions: ['.vue', '.js', '.jsx', '.json']
  32. },
  33. esbuild: { loader: { '.js': '.jsx' }},
  34. plugins: [
  35. createVuePlugin({
  36. jsx: true
  37. }),
  38. // eslintPlugin(),
  39. legacy({
  40. targets: ['ie >= 11'],
  41. additionalLegacyPolyfills: ['regenerator-runtime/runtime']
  42. }),
  43. viteCompression()
  44. ]
  45. })
  46. }