vite.config.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { resolve } from "path";
  4. import fs from "fs";
  5. import dotenv from "dotenv";
  6. import postCssPxToRem from "postcss-pxtorem";
  7. import legacyPlugin from "@vitejs/plugin-legacy";
  8. // https://vitejs.dev/config/
  9. export default defineConfig(({ mode }) => {
  10. console.log("mode", mode);
  11. const ASR_ENV = dotenv.parse(fs.readFileSync(`.env.${mode}`));
  12. console.log("ASR_ENV", ASR_ENV);
  13. return {
  14. plugins: [
  15. vue(),
  16. legacyPlugin({
  17. targets: ["ie >= 11"], // 需要兼容的目标列表,可以设置多个
  18. additionalLegacyPolyfills: ["regenerator-runtime/runtime"], // 面向IE11时需要此插件
  19. renderLegacyChunks: true,
  20. polyfills: [
  21. 'es.symbol',
  22. 'es.array.filter',
  23. 'es.promise',
  24. 'es.promise.finally',
  25. 'es/map',
  26. 'es/set',
  27. 'es.array.for-each',
  28. 'es.object.define-properties',
  29. 'es.object.define-property',
  30. 'es.object.get-own-property-descriptor',
  31. 'es.object.get-own-property-descriptors',
  32. 'es.object.keys',
  33. 'es.object.to-string',
  34. 'web.dom-collections.for-each',
  35. 'esnext.global-this',
  36. 'esnext.string.match-all'
  37. ],
  38. }),
  39. ],
  40. assetsInclude: ["**/*.mov"],
  41. base: "/sgdaping/",
  42. //publicDir:'dist/sgshow',
  43. build: {
  44. outDir: "dist/sgdaping",
  45. target: 'es2015'
  46. },
  47. css: {
  48. postcss: {
  49. plugins: [
  50. postCssPxToRem({
  51. rootValue: 192, // 1rem的大小
  52. propList: ["*", "!border"], // 需要转换的属性,这里选择全部都进行转换
  53. }),
  54. ],
  55. },
  56. },
  57. server: {
  58. port: 3000,
  59. open: true,
  60. host: "0.0.0.0",
  61. //https: true,
  62. //cors: true,
  63. proxy: {
  64. // [ASR_ENV.VITE_BASE_API]: {
  65. // target: `${ASR_ENV.VITE_TARGET_HOST}`,
  66. // changeOrigin: true,
  67. // },
  68. "/sgdaping/duoduo-service": {
  69. target: "https://duoduoenv.sagacloud.cn",
  70. changeOrigin: true,
  71. rewrite: (path) =>
  72. path.replace(/^\/sgdaping\/duoduo-service/, "/duoduo-service"),
  73. },
  74. },
  75. },
  76. resolve: {
  77. alias: {
  78. "@": resolve(__dirname, ".", "src"),
  79. },
  80. },
  81. };
  82. });