| | |
| | | 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, |
| | |
| | | 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(), |
| | | |
| | |
| | | }) |
| | | }, |
| | | }, |
| | | // qiankun(pkg.name, { |
| | | // useDevMode: true, |
| | | // lazyImport({ |
| | | // resolvers: [ |
| | | // VxeResolver({ |
| | | // libraryName: 'vxe-table', |
| | | // }), |
| | | // ], |
| | | // }), |
| | | optimizeLodashImports(), |
| | | topLevelAwait({ |
| | | promiseExportName: '__tla', |
| | | promiseImportName: (i) => `__tla_${i}`, |
| | | }), |
| | | vitePluginForArco({ |
| | | style: 'css', |
| | | }), |
| | | ], |
| | | resolve: { |
| | | alias: { |
| | |
| | | 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, |
| | | }, |
| | |
| | | }, |
| | | }, |
| | | 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, |
| | | }, |
| | | }, |
| | | }, |
| | | } |