vite.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. let dev = {
  6. // shaoyang: `http://42.48.99.5:20002`
  7. // shaoyang: `http://192.168.110.235:20002`
  8. shaoyang: `http://192.168.110.13:20002`
  9. }
  10. export default defineConfig(({ mode, command }) => {
  11. const env = loadEnv(mode, process.cwd())
  12. const { VITE_APP_ENV } = env
  13. return {
  14. base: VITE_APP_ENV === 'production' ? '/' : '/',
  15. plugins: createVitePlugins(env, command === 'build'),
  16. resolve: {
  17. // https://cn.vitejs.dev/config/#resolve-alias
  18. alias: {
  19. // 设置路径
  20. '~': path.resolve(__dirname, './'),
  21. // 设置别名
  22. '@': path.resolve(__dirname, './src')
  23. },
  24. // https://cn.vitejs.dev/config/#resolve-extensions
  25. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  26. },
  27. // vite 相关配置
  28. server: {
  29. port: 8081,
  30. host: true,
  31. open: true,
  32. proxy: {
  33. // https://cn.vitejs.dev/config/#server-proxy
  34. '/dev-api': {
  35. target: dev.shaoyang,
  36. changeOrigin: true,
  37. rewrite: (p) => p.replace(/^\/dev-api/, '')
  38. }
  39. }
  40. },
  41. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  42. css: {
  43. postcss: {
  44. plugins: [
  45. {
  46. postcssPlugin: 'internal:charset-removal',
  47. AtRule: {
  48. charset: (atRule) => {
  49. if (atRule.name === 'charset') {
  50. atRule.remove()
  51. }
  52. }
  53. }
  54. }
  55. ]
  56. }
  57. }
  58. }
  59. })