vite.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import alias from "@rollup/plugin-alias";
  4. import createVitePlugins from './vite/plugins'
  5. import resolveExternalsPlugin from 'vite-plugin-resolve-externals'
  6. // https://vitejs.dev/config/
  7. export default defineConfig(({ mode, command }) => {
  8. const env = loadEnv(mode, process.cwd())
  9. const { VITE_APP_ENV } = env
  10. plugins: [alias(),
  11. resolveExternalsPlugin({
  12. AMap: 'AMap'
  13. }),
  14. ]
  15. const config = loadEnv(mode, './')
  16. return {
  17. // 部署生产环境和开发环境下的URL。
  18. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  19. base: VITE_APP_ENV === 'production' ? '/' : '/',
  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. build: {
  33. rollupOptions: {
  34. external: [
  35. "Vue3SeamlessScroll"
  36. ]
  37. },
  38. //<----------去除console------
  39. minify: 'terser',
  40. terserOptions: {
  41. compress: {
  42. drop_console: true,
  43. drop_debugger: true
  44. }
  45. },
  46. //-----------去除console----->
  47. },
  48. // vite 相关配置
  49. server: {
  50. hmr: true, //热更新
  51. port: 81, //端口号
  52. host: true,
  53. open: true, // 自动打开浏览器
  54. proxy: {
  55. '/dev-api': {
  56. // target: 'http://gateWay.usky.cn',
  57. target: 'http://172.16.120.165:13200',
  58. // target: 'http://172.16.120.233:9886',
  59. // target: 'http://park.usky.cn/dev-api/',
  60. ws: true,
  61. changeOrigin: true,
  62. pathRewrite: {
  63. '^/api': ''
  64. },
  65. //rewrite: (p) => p.replace(/^\/dev-api/, '')
  66. },
  67. '/prod-api': {
  68. // target: 'http://gateWay.usky.cn',
  69. target: 'http://gateway.usky.cn',
  70. // target: 'http://172.17.35.51:13200/',
  71. ws: true,
  72. changeOrigin: true,
  73. pathRewrite: {
  74. '^/api': ''
  75. },
  76. //rewrite: (p) => p.replace(/^\/dev-api/, '')
  77. },
  78. },
  79. },
  80. css: {
  81. postcss: {
  82. plugins: [{
  83. postcssPlugin: 'internal:charset-removal',
  84. AtRule: {
  85. charset: (atRule) => {
  86. if (atRule.name === 'charset') {
  87. atRule.remove();
  88. }
  89. }
  90. }
  91. }]
  92. }
  93. },
  94. // configureWebpack() {
  95. // return {
  96. // extensions: ['.AMap']
  97. // }
  98. // },
  99. }
  100. })