Sin descripción

vite.config.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. import vue from '@vitejs/plugin-vue'
  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. base: VITE_APP_ENV === 'production' ? '/' : '/',
  14. plugins: createVitePlugins(env, command === 'build'),
  15. resolve: {
  16. // https://cn.vitejs.dev/config/#resolve-alias
  17. alias: {
  18. // 设置路径
  19. 'vue': 'vue/dist/vue.esm-bundler.js',
  20. '~': path.resolve(__dirname, './'),
  21. 'dayjs': path.resolve(__dirname, 'node_modules/dayjs'),
  22. // 设置别名
  23. '@': path.resolve(__dirname, './src')
  24. },
  25. optimizeDeps: {
  26. include: ['vue', 'gantt-elastic']
  27. },
  28. // https://cn.vitejs.dev/config/#resolve-extensions
  29. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  30. },
  31. // vite 相关配置
  32. server: {
  33. port: 80,
  34. host: true,
  35. open: true,
  36. proxy: {
  37. // https://cn.vitejs.dev/config/#server-proxy
  38. '/dev-api': {
  39. target: 'http://localhost:8080',
  40. changeOrigin: true,
  41. rewrite: (p) => p.replace(/^\/dev-api/, '')
  42. }
  43. }
  44. },
  45. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  46. css: {
  47. postcss: {
  48. plugins: [
  49. {
  50. postcssPlugin: 'internal:charset-removal',
  51. AtRule: {
  52. charset: (atRule) => {
  53. if (atRule.name === 'charset') {
  54. atRule.remove()
  55. }
  56. }
  57. }
  58. }
  59. ]
  60. }
  61. }
  62. }
  63. })