vite.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd())
  7. return {
  8. // 部署生产环境和开发环境下的URL。
  9. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  10. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  11. base: env.VITE_APP_CONTEXT_PATH,
  12. build: {
  13. chunkSizeWarningLimit: 10240
  14. },
  15. plugins: createVitePlugins(env, command === 'build'),
  16. resolve: {
  17. // https://cn.vitejs.dev/config/#resolve-alias
  18. alias: {
  19. // 设置路径
  20. '~': path.resolve(__dirname, './'),
  21. // 设置别名
  22. '@': path.resolve(__dirname, './src')
  23. },
  24. // https://cn.vitejs.dev/config/#resolve-extensions
  25. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  26. },
  27. // vite 相关配置
  28. server: {
  29. port: env.VITE_APP_PORT,
  30. host: true,
  31. open: true,
  32. proxy: {
  33. // https://cn.vitejs.dev/config/#server-proxy
  34. '/dev-api': {
  35. target: 'http://localhost:8110',
  36. changeOrigin: true,
  37. rewrite: (p) => p.replace(/^\/dev-api/, '')
  38. }
  39. }
  40. },
  41. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  42. css: {
  43. postcss: {
  44. plugins: [
  45. {
  46. postcssPlugin: 'internal:charset-removal',
  47. AtRule: {
  48. charset: (atRule) => {
  49. if (atRule.name === 'charset') {
  50. atRule.remove();
  51. }
  52. }
  53. }
  54. }
  55. ]
  56. }
  57. }
  58. }
  59. })