ÎļþÃû´Ó WMS/web/vite.config.ts ÐÞ¸Ä |
| | |
| | | |
| | | 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) |
| | |
| | | // requireTransform({}), |
| | | vueJsx(), |
| | | vue({ |
| | | // @ts-ignore |
| | | reactivityTransform: path.resolve(__dirname, 'src'), |
| | | }), |
| | | VueTypeImports(), |
| | |
| | | ws: true, |
| | | }, |
| | | '/projectApi': { |
| | | target: `http://127.0.0.1:${projectPort}`, |
| | | target: env.VITE_PROJECT_API_URL, |
| | | changeOrigin: true, |
| | | ws: true, |
| | | }, |