import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import { resolve } from "path"; import fs from "fs"; import dotenv from "dotenv"; import postCssPxToRem from "postcss-pxtorem"; import legacyPlugin from "@vitejs/plugin-legacy"; // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { console.log("mode", mode); const ASR_ENV = dotenv.parse(fs.readFileSync(`.env.${mode}`)); console.log("ASR_ENV", ASR_ENV); return { plugins: [ vue(), legacyPlugin({ targets: ["ie >= 11"], // 需要兼容的目标列表,可以设置多个 additionalLegacyPolyfills: ["regenerator-runtime/runtime"], // 面向IE11时需要此插件 renderLegacyChunks: true, polyfills: [ 'es.symbol', 'es.array.filter', 'es.promise', 'es.promise.finally', 'es/map', 'es/set', 'es.array.for-each', 'es.object.define-properties', 'es.object.define-property', 'es.object.get-own-property-descriptor', 'es.object.get-own-property-descriptors', 'es.object.keys', 'es.object.to-string', 'web.dom-collections.for-each', 'esnext.global-this', 'esnext.string.match-all' ], }), ], assetsInclude: ["**/*.mov"], base: "/sgdaping/", //publicDir:'dist/sgshow', build: { outDir: "dist/sgdaping", target: 'es2015' }, css: { postcss: { plugins: [ postCssPxToRem({ rootValue: 192, // 1rem的大小 propList: ["*", "!border"], // 需要转换的属性,这里选择全部都进行转换 }), ], }, }, server: { port: 3000, open: true, host: "0.0.0.0", //https: true, //cors: true, proxy: { // [ASR_ENV.VITE_BASE_API]: { // target: `${ASR_ENV.VITE_TARGET_HOST}`, // changeOrigin: true, // }, "/sgdaping/duoduo-service": { target: "https://duoduoenv.sagacloud.cn", changeOrigin: true, rewrite: (path) => path.replace(/^\/sgdaping\/duoduo-service/, "/duoduo-service"), }, }, }, resolve: { alias: { "@": resolve(__dirname, ".", "src"), }, }, }; });