vite.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. plugins: createVitePlugins(env, command === 'build'),
  15. base: VITE_APP_ENV === 'production' ? '/' : '/',
  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: 80,
  30. host: true,
  31. open: true,
  32. proxy: {
  33. // https://cn.vitejs.dev/config/#server-proxy
  34. '/dev-api': {
  35. target: 'http://localhost:8080',
  36. changeOrigin: true,
  37. rewrite: (p) => p.replace(/^\/dev-api/, '')
  38. },
  39. '/uploadPath': {
  40. target: `http://mz.tshe.cn:801/uploadPath`,
  41. changeOrigin: true,
  42. rewrite: (p) => p.replace(/^\/uploadPath/, '')
  43. }
  44. }
  45. },
  46. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  47. css: {
  48. postcss: {
  49. plugins: [
  50. {
  51. postcssPlugin: 'internal:charset-removal',
  52. AtRule: {
  53. charset: (atRule) => {
  54. if (atRule.name === 'charset') {
  55. atRule.remove()
  56. }
  57. }
  58. }
  59. }
  60. ]
  61. }
  62. }
  63. }
  64. })