vite.config.js 2.4 KB

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