From 9bec4dcae002f36aa23231da11cb03a156b40110 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周三, 30 4月 2025 16:24:16 +0800 Subject: [PATCH] 222 --- PipeLineLems/web/vite.config.ts | 135 +++++++++++++++++++++----------------------- 1 files changed, 64 insertions(+), 71 deletions(-) diff --git a/PipeLineLems/web/vite.config.ts b/PipeLineLems/web/vite.config.ts index c0925aa..96c34ae 100644 --- a/PipeLineLems/web/vite.config.ts +++ b/PipeLineLems/web/vite.config.ts @@ -2,64 +2,29 @@ import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' import path from 'path' +import slash from 'slash' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' -import qiankun from 'vite-plugin-qiankun' -import pkg from './package.json' import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin' import VueTypeImports from 'vite-plugin-vue-type-imports' +import topLevelAwait from 'vite-plugin-top-level-await' +import svgIcon from 'vite-plugin-svgicon' +import VitePluginDevelopmentFilter from './script/plugins/vite-plugin-development-filter' +import { vitePluginForArco } from '@arco-plugins/vite-vue' import { ChildProcess } from 'child_process' -import slash from 'slash' const kill = require('kill-port') const crossSpawn = require('cross-spawn') +const tag = 'information-debugger' +const prodTag = 'information-prod' const isWin = process.platform === 'win32' const appPath = slash(path.resolve(process.cwd(), 'app')) -const getPort: () => Promise<string> = () => { +const runGoServer = () => { const child: ChildProcess = crossSpawn( isWin - ? '..\\node_modules\\lmes-create-widget\\port' - : '../node_modules/lmes-create-widget/port', - [], //娣诲姞绔彛鍜岀幆澧冨彉閲忓弬鏁� - { - cwd: appPath, - shell: true, - env: { - ENV: 'production', - }, - } - ) - - let output = '' - return new Promise((resolve, reject) => { - // 鑾峰彇瀛愯繘绋嬬殑鏍囧噯杈撳嚭 - child.stdout?.on('data', (data) => { - output += data.toString() - }) - - child.stderr?.on('data', (data) => { - console.error('stderr:', data.toString()) - }) - - child.on('close', (code) => { - if (code === 0) { - const port = output.split('\n')[0] - console.log('PROJECT_PORT:', port) - resolve(port) - } else { - reject(code) - } - }) - }) -} - -const runGoServer = (projectPort: string) => { - const child: ChildProcess = crossSpawn( - isWin - ? `..\\node_modules\\lmes-create-widget\\www ${projectPort}` - : `../node_modules/lmes-create-widget/www ${projectPort}`, - [], //娣诲姞绔彛鍜岀幆澧冨彉閲忓弬鏁� + ? '..\\node_modules\\lmes-create-widget\\www' + : '../node_modules/lmes-create-widget/www', { stdio: 'inherit', cwd: appPath, @@ -83,43 +48,52 @@ process.exit(0) } } -const run = (projectPort: string) => { +const run = () => { try { - runGoServer(projectPort) + runGoServer() let lastPressTime = Date.now() process.on('SIGINT', async () => { const currentTime = Date.now() if (lastPressTime && currentTime - lastPressTime < 2000) { - killGoServer(Number(projectPort)) + killGoServer(8800) } else { lastPressTime = Date.now() } }) process.on('SIGTERM', () => { console.log('杩涚▼琚� kill 缁堟...') - killGoServer(Number(projectPort)) + killGoServer(8800) }) } catch (error) { console.error(error) } } +run() // @ts-ignore -export default defineConfig(async ({ mode }) => { - const projectPort = await getPort() - run(projectPort) +export default defineConfig(({ mode }) => { const env = loadEnv(mode, __dirname) - console.info('[mode]', mode) console.info('[env]', env) - + const vueBaseConfig = { + template: { + compilerOptions: { + isCustomElement: (id) => [tag].includes(id), + }, + }, + } return { - // base: `//localhost:${env.VITE_PORT}/`, base: '/', + define: { + 'process.env.VITE_STATIC_URL': '""', + }, plugins: [ - // requireTransform({}), - vueJsx(), + VitePluginDevelopmentFilter({ prodTag, tag }), + vueJsx(vueBaseConfig.template.compilerOptions), vue({ - // @ts-ignore - reactivityTransform: path.resolve(__dirname, 'src'), + ...vueBaseConfig, + // reactivityTransform: path.resolve(__dirname, 'src'), + }), + svgIcon({ + include: [slash(path.resolve('./src/assets/svg-icon/*.svg'))], }), VueTypeImports(), @@ -141,10 +115,21 @@ }) }, }, - // qiankun(pkg.name, { - // useDevMode: true, + // lazyImport({ + // resolvers: [ + // VxeResolver({ + // libraryName: 'vxe-table', + // }), + // ], // }), optimizeLodashImports(), + topLevelAwait({ + promiseExportName: '__tla', + promiseImportName: (i) => `__tla_${i}`, + }), + vitePluginForArco({ + style: 'css', + }), ], resolve: { alias: { @@ -174,13 +159,22 @@ target: env.VITE_API_URL, changeOrigin: true, }, + '/flows': { + target: env.VITE_API_URL, + changeOrigin: true, + }, '/hubs': { target: env.VITE_API_URL, changeOrigin: true, ws: true, }, + '/resources': { + target: env.VITE_STATIC_URL, + changeOrigin: true, + ws: true, + }, '/projectApi': { - target: `http://127.0.0.1:${projectPort}`, + target: env.VITE_PROJECT_API_URL, changeOrigin: true, ws: true, }, @@ -199,24 +193,23 @@ }, }, esbuild: { - drop: mode !== 'development' ? ['console', 'debugger'] : [], + drop: mode !== 'development' ? ['debugger'] : [], keepNames: true, }, css: { - // postcss: { - // plugins: [ - // PurgeCSS({ - // // PurgeCSS options here - // content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], - // }), - // ], - // }, preprocessorOptions: { scss: { additionalData: ` @use "@/assets/styles/element.scss" as *; `, }, + less: { + modifyVars: { + 'arcoblue-6': '#f85959', + '--primary-6': '#5a84ff', + }, + javascriptEnabled: true, + }, }, }, } -- Gitblit v1.9.3