123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import { defineConfig, loadEnv } from "vite";
- import vue from "@vitejs/plugin-vue";
- import path from "path";
- import AutoImport from "unplugin-auto-import/vite";
- import Components from "unplugin-vue-components/vite";
- import { TDesignResolver } from "unplugin-vue-components/resolvers";
- import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
- import zipBuildPlugin from './zipBuildPlugin';
- import vueJsx from '@vitejs/plugin-vue-jsx';
- // https://vitejs.dev/config/
- export default defineConfig(({ mode }) => {
- const ENV = loadEnv(mode, process.cwd());
- return {
- base: ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
- plugins: [
- vue(),
- vueJsx(),
- AutoImport({
- // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
- imports: ["vue"],
- dirs: ["./src/plugin"], // 自动扫描并导入 `src/plugin` 下的方法
- resolvers: [
- TDesignResolver({
- library: "vue-next",
- }),
- ],
- dts: "src/auto-imports.d.ts", // 自动生成类型声明文件
- }),
- Components({
- resolvers: [
- TDesignResolver({
- library: "vue-next",
- }),
- // 由于tdesign 官方未在unplugin-vue-components 处理自动导入指令的情况
- // 所以手动导入下
- {
- type: 'directive',
- resolve: (name) => {
- if (name === 'Loading') {
- return {
- name: 'vLoading',
- from: `tdesign-vue-next/esm/loading/directive`
- };
- } else {
- return;
- }
- },
- }
- ],
- directives: true
- }),
- createSvgIconsPlugin({
- // 指定需要缓存的图标文件夹
- iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
- // 指定symbolId格式
- symbolId: "[name]",
- /**
- * 自定义插入位置
- * @default: body-last
- */
- // inject?: 'body-last' | 'body-first'
- /**
- * custom dom id
- * @default: __svg__icons__dom__
- */
- // customDomId: '__svg__icons__dom__'
- }),
- zipBuildPlugin()
- ],
- css: {
- // css预处理器
- preprocessorOptions: {
- scss: {
- // 定义全局的scss变量
- // 给导入的路径最后加上 ;
- additionalData: `@import '@/styles/var.scss';`,
- },
- },
- },
- resolve: {
- alias: {
- "@": path.resolve(__dirname, "./src"),
- },
- },
- build: {
- outDir: ENV.VITE_APP_OUTDIR,
- },
- server:{
- port:8900,
- proxy:{
- '/v1': {
- // target: 'http://192.168.20.10:8912/v1',
- target: 'http://8.136.199.33:8900/v1',
- // target: 'http://8.136.199.33:7777/adminapi/',
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/v1/, ''),
- }
- }
- }
- };
- });
|