vite.config.js 2.4 KB

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