vite.config.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite';
  2. import createPlugins from './vite/plugins';
  3. import path from 'path';
  4. export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
  5. const env = loadEnv(mode, process.cwd());
  6. return {
  7. // 部署生产环境和开发环境下的URL。
  8. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  9. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  10. base: env.VITE_APP_CONTEXT_PATH,
  11. resolve: {
  12. alias: {
  13. '~': path.resolve(__dirname, './'),
  14. '@': path.resolve(__dirname, './src')
  15. },
  16. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  17. },
  18. // https://cn.vitejs.dev/config/#resolve-extensions
  19. plugins: createPlugins(env, command === 'build'),
  20. server: {
  21. host: '0.0.0.0',
  22. port: Number(env.VITE_APP_PORT),
  23. open: true,
  24. proxy: {
  25. // [env.VITE_APP_BASE_API]: {
  26. // // target: 'http://localhost:8080',
  27. // target: 'http://10.181.7.236:9988',
  28. // changeOrigin: true,
  29. // ws: true,
  30. // rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  31. // }
  32. }
  33. },
  34. css: {
  35. preprocessorOptions: {
  36. scss: {
  37. javascriptEnabled: true
  38. }
  39. },
  40. postcss: {
  41. plugins: [
  42. {
  43. postcssPlugin: 'internal:charset-removal',
  44. AtRule: {
  45. charset: (atRule) => {
  46. if (atRule.name === 'charset') {
  47. atRule.remove();
  48. }
  49. }
  50. }
  51. }
  52. ]
  53. }
  54. },
  55. // 预编译
  56. optimizeDeps: {
  57. include: ['/node_modules/']
  58. },
  59. build: {
  60. rollupOptions: {
  61. output: {
  62. chunkFileNames: 'static/js/[name]-[hash].js',
  63. entryFileNames: 'static/js/[name]-[hash].js',
  64. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  65. }
  66. }
  67. }
  68. };
  69. });