vite.config.js 2.3 KB

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