vite.config.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // https://cn.vitejs.dev/config/#server-proxy
  45. '/sh-api': {
  46. target: env.VITE_DEV_PATH,
  47. changeOrigin: true,
  48. rewrite: (p) => p.replace(/^\/sh-api/, '')
  49. }
  50. // [env.VITE_APP_BASE_API]: {
  51. // target: env.VITE_DEV_PATH,
  52. // changeOrigin: true,
  53. // pathRewrite: {
  54. // ['^' + env.VITE_APP_BASE_API]: ''
  55. // }
  56. // }
  57. }
  58. },
  59. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  60. css: {
  61. postcss: {
  62. plugins: [
  63. {
  64. postcssPlugin: 'internal:charset-removal',
  65. AtRule: {
  66. charset: (atRule) => {
  67. if (atRule.name === 'charset') {
  68. atRule.remove();
  69. }
  70. }
  71. }
  72. }
  73. ]
  74. }
  75. }
  76. }
  77. })