vite.config.js 3.2 KB

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