1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { defineConfig, loadEnv } from "vite";
- import vue from "@vitejs/plugin-vue";
- import path from "path";
- import Icons from "unplugin-icons/vite";
- import IconsResolver from "unplugin-icons/resolver";
- import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
- import AutoImport from 'unplugin-auto-import/vite';
- import Components from 'unplugin-vue-components/vite';
- import { TDesignResolver } from 'unplugin-vue-components/resolvers';
- import zipBuildPlugin from './zipBuildPlugin';
- import compress from 'vite-plugin-compression'
- // https://vitejs.dev/config/
- export default defineConfig(({ mode }) => {
- const ENV = loadEnv(mode, process.cwd());
- return {
- base: ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
- plugins: [
- vue(),
- AutoImport({
- // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
- imports: ["vue"],
- resolvers: [TDesignResolver({
- library: 'mobile-vue'
- })],
- }),
- Components({
- resolvers: [TDesignResolver({
- library: 'mobile-vue'
- })],
- }),
- 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__'
- }),
- compress({
- algorithm: 'gzip',
- ext: '.gz'
- }),
- {
- name: 'custom-zip-plugin',
- apply: 'build',
- closeBundle() {
- setTimeout(() => {
- const plugin = zipBuildPlugin(ENV.VITE_APP_OUTDIR);
- return plugin.closeBundle.handler();
- }, 1000);
- }
- }
- ],
- css: {
- // css预处理器
- preprocessorOptions: {
- scss: {
- // 定义全局的scss变量
- // 给导入的路径最后加上 ;
- // additionalData: `@import '@/styles/var.scss';`,
- },
- },
- },
- resolve: {
- alias: {
- "@": path.resolve(__dirname, "./src"),
- },
- },
- build: {
- outDir: ENV.VITE_APP_OUTDIR,
- },
- server: {
- port: 8708,
- proxy: {
- "/api": {
- target: "http://8.136.199.33:8709/api",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ""),
- },
- },
- },
- };
- });
|