vite.config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd())
  7. const { VITE_APP_ENV } = env
  8. return {
  9. // 部署生产环境和开发环境下的URL。
  10. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  11. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  12. base: VITE_APP_ENV === 'production' ? '/' : '/',
  13. plugins: createVitePlugins(env, command === 'build'),
  14. resolve: {
  15. // https://cn.vitejs.dev/config/#resolve-alias
  16. alias: {
  17. // 设置路径
  18. '~': path.resolve(__dirname, './'),
  19. // 设置别名
  20. '@': path.resolve(__dirname, './src')
  21. },
  22. // https://cn.vitejs.dev/config/#resolve-extensions
  23. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  24. },
  25. // 打包配置
  26. build: {
  27. // https://vite.dev/config/build-options.html
  28. sourcemap: command === 'build' ? false : 'inline',
  29. outDir: 'dist',
  30. assetsDir: 'assets',
  31. chunkSizeWarningLimit: 2000,
  32. rollupOptions: {
  33. output: {
  34. chunkFileNames: 'static/js/[name]-[hash].js',
  35. entryFileNames: 'static/js/[name]-[hash].js',
  36. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  37. }
  38. }
  39. },
  40. // vite 相关配置
  41. server: {
  42. port: 80,
  43. host: true,
  44. open: true,
  45. proxy: {
  46. // https://cn.vitejs.dev/config/#server-proxy
  47. '/dev-api': {
  48. target: 'http://localhost:8080',
  49. // target: 'http://192.168.3.100:8080',//临时11
  50. changeOrigin: true,
  51. rewrite: (p) => p.replace(/^\/dev-api/, '')
  52. }
  53. }
  54. },
  55. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  56. css: {
  57. postcss: {
  58. plugins: [
  59. {
  60. postcssPlugin: 'internal:charset-removal',
  61. AtRule: {
  62. charset: (atRule) => {
  63. if (atRule.name === 'charset') {
  64. atRule.remove()
  65. }
  66. }
  67. }
  68. }
  69. ]
  70. }
  71. }
  72. }
  73. })