vite.config.js 2.4 KB

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