vite.config.js 1.5 KB

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