This commit is contained in:
39
scripts/dev-web-rust.mjs
Normal file
39
scripts/dev-web-rust.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
import {spawn} from 'node:child_process';
|
||||
|
||||
const mergedEnv = {
|
||||
...process.env,
|
||||
RUST_SERVER_TARGET:
|
||||
process.env.RUST_SERVER_TARGET ||
|
||||
process.env.GENARRATIVE_API_TARGET ||
|
||||
`http://127.0.0.1:${process.env.GENARRATIVE_API_PORT || '3100'}`,
|
||||
};
|
||||
|
||||
mergedEnv.GENARRATIVE_RUNTIME_SERVER_TARGET =
|
||||
process.env.GENARRATIVE_RUNTIME_SERVER_TARGET || mergedEnv.RUST_SERVER_TARGET;
|
||||
|
||||
console.log(`[dev:web] backend=rust target=${mergedEnv.GENARRATIVE_RUNTIME_SERVER_TARGET}`);
|
||||
|
||||
const child = spawn(
|
||||
'node',
|
||||
['scripts/vite-cli.mjs', '--port=3000', '--host=0.0.0.0'],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: mergedEnv,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32',
|
||||
},
|
||||
);
|
||||
|
||||
child.on('error', (error) => {
|
||||
console.error(`[dev:web] 启动 Vite 失败: ${error.message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
child.on('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
console.error(`[dev:web] Vite 被信号终止: ${signal}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
Reference in New Issue
Block a user