vite.config.js 2.0 KB

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