| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { defineConfig, loadEnv, ConfigEnv } from "vite";
- import vue from "@vitejs/plugin-vue";
- import path from "path";
- import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
- import AutoImport from "unplugin-auto-import/vite";
- import Components from "unplugin-vue-components/vite";
- import IconsResolver from "unplugin-icons/resolver";
- import Icons from "unplugin-icons/vite";
- import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
- import { VueUseComponentsResolver } from "unplugin-vue-components/resolvers";
- import postcsspxtoviewport from "postcss-px-to-viewport";
- import legacyPlugin from "@vitejs/plugin-legacy";
- // https://vitejs.dev/config/
- export default ({ mode }: ConfigEnv) => {
- const env = loadEnv(mode, process.cwd());
- return defineConfig({
- plugins: [
- vue(),
- createSvgIconsPlugin({
- iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
- symbolId: "icon-[dir]-[name]",
- }),
- AutoImport({
- imports: ["vue", "vue-router", "pinia", "@vueuse/core", { axios: [["default", "axios"]] }],
- resolvers: [ElementPlusResolver(), IconsResolver({})],
- vueTemplate: true,
- dts: path.resolve(__dirname, "types", "auto-imports.d.ts"),
- }),
- Components({
- resolvers: [ElementPlusResolver(), IconsResolver({ prefix: "icon", enabledCollections: ["ep"] }), VueUseComponentsResolver()],
- dts: path.resolve(__dirname, "types", "components.d.ts"),
- }),
- // 图标库 'https://fontawesome.com.cn/v5' 'https://icones.netlify.app/' 'https://icon-sets.iconify.design/'
- Icons({ autoInstall: true }),
- legacyPlugin({
- targets: ["chrome 52"], // 需要兼容的目标列表,可以设置多个
- additionalLegacyPolyfills: ["regenerator-runtime/runtime"], // 面向IE11时需要此插件
- }),
- ],
- resolve: {
- alias: {
- "@": path.resolve(__dirname, "./src"),
- },
- },
- css: {
- preprocessorOptions: {
- scss: {
- additionalData: `@import "@/assets/styles/variables.scss";`,
- javascriptEnabled: true,
- },
- },
- postcss: {
- plugins: [
- postcsspxtoviewport({
- unitToConvert: "px", // 要转化的单位
- viewportWidth: 1920, // 要转化的单位
- unitPrecision: 6, // 转换后的精度,即小数点位数
- propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
- viewportUnit: "vw", // 指定需要转换成的视窗单位,默认vw
- fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位,默认vw
- selectorBlackList: [], // 指定不转换为视窗单位的类名,
- minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
- mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
- replace: true, // 是否转换后直接更换属性值
- landscape: false, // 是否处理横屏情况
- }),
- ],
- },
- },
- // server: {
- // host: "0.0.0.0",
- // port: 80,
- // proxy: {
- // "/api": {
- // target: "http://localhost:8080",
- // ws: true,
- // changeOrigin: true,
- // rewrite: (path) => path.replace(/^\/api/, ""),
- // },
- // },
- // },
- });
- };
|