vite.config.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "report-share": resolve(__dirname, "report-share.html"),
  40. instrument: resolve(__dirname, "instrument.html"),
  41. },
  42. output: {
  43. chunkFileNames: "js/[name]-[hash].js", // 引入文件名的名称
  44. entryFileNames: "js/[name]-[hash].js", // 包的入口文件名称
  45. assetFileNames: "[ext]/[name]-[hash].[ext]", // 资源文件像 字体,图片等
  46. },
  47. },
  48. },
  49. server: {
  50. cors: true,
  51. port: 3000,
  52. // https: true,
  53. proxy: {
  54. "^/instrument/.*": {
  55. target: "https://dev.gym.lexiaoya.cn",
  56. changeOrigin: true,
  57. rewrite: (path) => path.replace(/^\/instrument/, ""),
  58. },
  59. },
  60. },
  61. preview: {
  62. port: 3000,
  63. host: "192.168.3.114",
  64. },
  65. });
  66. // vite.config.js