vite.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig } from "vite";
  3. import { babel } from '@rollup/plugin-babel';
  4. import vue2 from "@vitejs/plugin-vue2";
  5. import vue2Jsx from "@vitejs/plugin-vue2-jsx";
  6. import legacy from "@vitejs/plugin-legacy";
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. plugins: [
  10. vue2(),
  11. vue2Jsx(),
  12. legacy({
  13. targets: ["ie >= 11"],
  14. additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
  15. }),
  16. ],
  17. resolve: {
  18. alias: {
  19. "@": fileURLToPath(new URL("./src", import.meta.url)),
  20. },
  21. },
  22. server: {
  23. // 是否开启 https
  24. https: false,
  25. // 端口号
  26. // port: 3000,
  27. // 监听所有地址
  28. host: "0.0.0.0",
  29. // 服务启动时是否自动打开浏览器
  30. open: true,
  31. // 允许跨域
  32. cors: true,
  33. // 自定义代理规则
  34. proxy: {
  35. "/camera-api": {
  36. target: "https://ycjk.cq119.gov.cn",
  37. changeOrigin: true,
  38. rewrite: (path) => path.replace(/^\/camera-api/, ""),
  39. }
  40. },
  41. },
  42. build: {
  43. // 构建后是否生成 source map 文件
  44. sourcemap: false,
  45. // chunk 大小警告的限制(以 kbs 为单位)
  46. chunkSizeWarningLimit: 2000,
  47. // 启用/禁用 gzip 压缩大小报告
  48. reportCompressedSize: false,
  49. cssTarget: 'chrome70',
  50. target: 'es2015',
  51. rollupOptions: {
  52. plugins: [
  53. // https://www.npmjs.com/package/@rollup/plugin-babel
  54. babel({
  55. babelHelpers: 'bundled',
  56. presets: [
  57. [
  58. '@babel/preset-env',
  59. {
  60. useBuiltIns: 'entry', // 注意这里只能使用 entry
  61. corejs: '3',
  62. targets: 'last 2 versions and not dead, > 0.2%, Firefox ESR',
  63. },
  64. ],
  65. ],
  66. plugins: [],
  67. compact: false,
  68. })
  69. ]
  70. }
  71. },
  72. });