vite.config.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import vueJsx from "@vitejs/plugin-vue-jsx";
  4. import legacy from "@vitejs/plugin-legacy";
  5. import { resolve } from "path";
  6. import postCssPxToRem from "postcss-pxtorem";
  7. import { visualizer } from "rollup-plugin-visualizer";
  8. import viteCompression from "vite-plugin-compression";
  9. // https://vitejs.dev/config/
  10. export default defineConfig({
  11. base: "./",
  12. resolve: {},
  13. // assetsInclude: ['**/*.html'],
  14. plugins: [
  15. // mkcert(), // 本地https
  16. legacy({
  17. targets: ["Chrome 63"],
  18. additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
  19. modernPolyfills: true,
  20. }),
  21. vue(),
  22. vueJsx(),
  23. visualizer({ open: true }), // 自动开启分析页面
  24. ],
  25. css: {
  26. postcss: {
  27. plugins: [
  28. postCssPxToRem({
  29. rootValue: 37.5,
  30. propList: ["*"],
  31. selectorBlackList: [".norem"],
  32. }),
  33. ],
  34. },
  35. },
  36. build: {
  37. rollupOptions: {
  38. input: {
  39. instrument: resolve(__dirname, "instrument.html"),
  40. },
  41. output: {
  42. chunkFileNames: "js/[name]-[hash].js", // 引入文件名的名称
  43. entryFileNames: "js/[name]-[hash].js", // 包的入口文件名称
  44. assetFileNames: "[ext]/[name]-[hash].[ext]", // 资源文件像 字体,图片等
  45. },
  46. },
  47. },
  48. server: {
  49. cors: true,
  50. port: 3000,
  51. // https: true,
  52. proxy: {
  53. "^/instrument/.*": {
  54. target: "https://test.colexiu.com",
  55. changeOrigin: true,
  56. rewrite: (path) => path.replace(/^\/instrument/, ""),
  57. },
  58. },
  59. },
  60. preview: {
  61. port: 3000,
  62. host: "192.168.3.114",
  63. },
  64. });
  65. // vite.config.js