From 244e86dccfa1c102460b15e9b904833ad201ecf2 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 24 Apr 2025 16:14:57 +0800 Subject: [PATCH] =?UTF-8?q?build(vite):=20=E6=B7=BB=E5=8A=A0vite-plugin-st?= =?UTF-8?q?atic-copy=E6=8F=92=E4=BB=B6=E4=BB=A5=E5=A4=8D=E5=88=B6Swagger?= =?UTF-8?q?=20UI=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了在构建过程中将Swagger UI的相关资源复制到指定目录,引入了vite-plugin-static-copy插件。这确保了Swagger UI所需的静态文件能够正确部署到生产环境。 --- vite.config.mts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/vite.config.mts b/vite.config.mts index 6e5b61a..e284a81 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -1,10 +1,30 @@ import { URL, fileURLToPath } from 'node:url'; -import { defineConfig } from 'vite'; +import { defineConfig, normalizePath } from 'vite'; + import vue from '@vitejs/plugin-vue'; +import { viteStaticCopy } from 'vite-plugin-static-copy'; + +const { getAbsoluteFSPath } = await import('swagger-ui-dist'); +const swaggerUiPath = getAbsoluteFSPath(); // eslint-disable-next-line prefer-const const config = defineConfig({ - plugins: [vue()], + plugins: [ + vue(), + viteStaticCopy({ + targets: [ + { + src: [ + `${normalizePath(swaggerUiPath)}/*.{js,css,html,png}`, + `!${normalizePath(swaggerUiPath)}/**/index.html`, + normalizePath(fileURLToPath(new URL('./dist/axios.min.js', import.meta.resolve('axios/package.json')))), + normalizePath(fileURLToPath(new URL('./src/main/webapp/swagger-ui/index.html', import.meta.url))), + ], + dest: 'swagger-ui', + }, + ], + }), + ], root: fileURLToPath(new URL('./src/main/webapp/', import.meta.url)), publicDir: fileURLToPath(new URL('./target/classes/static/public', import.meta.url)), cacheDir: fileURLToPath(new URL('./target/.vite-cache', import.meta.url)),