vite.config.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. import tailwindcss from 'tailwindcss';
  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. const ENV_BASE_PATH = {
  10. development: '/',
  11. test: '/data/',
  12. production: '/'
  13. }
  14. const base = ENV_BASE_PATH[VITE_APP_ENV];
  15. return {
  16. // 部署生产环境和开发环境下的URL。
  17. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  18. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  19. base,
  20. plugins: createVitePlugins(env, command === 'build'),
  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: 80,
  35. host: true,
  36. open: true,
  37. proxy: {
  38. // https://cn.vitejs.dev/config/#server-proxy
  39. '/dev-api': {
  40. target: 'http://localhost:8080',
  41. changeOrigin: true,
  42. rewrite: (p) => p.replace(/^\/dev-api/, '')
  43. }
  44. }
  45. },
  46. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  47. css: {
  48. // loaderOptions: {
  49. // scss: {
  50. // sassOptions: {
  51. // outputStyle: "expanded"
  52. // },
  53. // prependData: '@import "@/assets/styles/custom-element.scss";'
  54. // }
  55. // },
  56. // loaderOptions: {
  57. // sass: {
  58. // additionalData: '@import "@/assets/styles/custom-element.scss";'
  59. // }
  60. // },
  61. postcss: {
  62. plugins: [
  63. tailwindcss,
  64. {
  65. postcssPlugin: 'internal:charset-removal',
  66. AtRule: {
  67. charset: (atRule) => {
  68. if (atRule.name === 'charset') {
  69. atRule.remove();
  70. }
  71. }
  72. }
  73. }
  74. ]
  75. }
  76. }
  77. }
  78. })