vite.config.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // [env.VITE_APP_BASE_API]: {
  50. // target: env.VITE_DEV_PATH,
  51. // changeOrigin: true,
  52. // pathRewrite: {
  53. // ['^' + env.VITE_APP_BASE_API]: ''
  54. // }
  55. // }
  56. }
  57. },
  58. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  59. css: {
  60. postcss: {
  61. plugins: [
  62. {
  63. postcssPlugin: 'internal:charset-removal',
  64. AtRule: {
  65. charset: (atRule) => {
  66. if (atRule.name === 'charset') {
  67. atRule.remove();
  68. }
  69. }
  70. }
  71. }
  72. ]
  73. }
  74. }
  75. }
  76. })