vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. '/visitor': {
  56. target: 'http://192.168.11.68',
  57. ws: true,
  58. changeOrigin: true,
  59. pathRewrite: {
  60. '^/api': ''
  61. },
  62. //rewrite: (p) => p.replace(/^\/dev-api/, '')
  63. },
  64. },
  65. },
  66. css: {
  67. postcss: {
  68. plugins: [{
  69. postcssPlugin: 'internal:charset-removal',
  70. AtRule: {
  71. charset: (atRule) => {
  72. if (atRule.name === 'charset') {
  73. atRule.remove();
  74. }
  75. }
  76. }
  77. }]
  78. }
  79. },
  80. // configureWebpack() {
  81. // return {
  82. // extensions: ['.AMap']
  83. // }
  84. // },
  85. }
  86. })