MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / startRspackWatch

Function startRspackWatch

utils/scripts/dev.js:313–382  ·  view source on GitHub ↗
(host, port, proto, onCompiled)

Source from the content-addressed store, hash-verified

311// ─── rspack watcher ──────────────────────────────────────────────────────────
312
313function startRspackWatch(host, port, proto, onCompiled) {
314 log("info", "Starting rspack --watch...");
315
316 const env = buildSpawnEnv({
317 DEV_MODE: "true",
318 DEV_HOST: host,
319 DEV_PORT: String(port),
320 DEV_PROTO: proto,
321 });
322 const rspackBin = path.join(
323 ROOT,
324 "node_modules",
325 "@rspack",
326 "cli",
327 "bin",
328 "rspack.js",
329 );
330
331 const useLocalRspack = fs.existsSync(rspackBin);
332 if (!useLocalRspack) {
333 log("warn", "Local rspack CLI not found, falling back to npx rspack");
334 }
335
336 const proc = useLocalRspack
337 ? spawn(process.execPath, [rspackBin, "--watch", "--mode", "development"], {
338 cwd: ROOT,
339 env,
340 stdio: "pipe",
341 })
342 : spawn(
343 resolveSpawnCommand("npx"),
344 ["rspack", "--watch", "--mode", "development"],
345 {
346 cwd: ROOT,
347 env,
348 stdio: "pipe",
349 },
350 );
351
352 let firstCompile = true;
353
354 proc.stdout.on("data", (chunk) => {
355 const text = chunk.toString();
356 process.stdout.write(text);
357 if (text.includes("compiled successfully") || text.includes("compiled")) {
358 if (firstCompile) {
359 firstCompile = false;
360 }
361 onCompiled();
362 }
363 });
364
365 proc.stderr.on("data", (chunk) => {
366 process.stderr.write(chunk);
367 });
368
369 proc.on("error", (err) => {
370 log("warn", `rspack error: ${err.message}`);

Callers 1

mainFunction · 0.85

Calls 8

buildSpawnEnvFunction · 0.85
StringInterface · 0.85
resolveSpawnCommandFunction · 0.85
exitMethod · 0.80
logFunction · 0.70
writeMethod · 0.65
onMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected