dev-tweak-serve-package-json
Tweak serving-related commands in package.json. Requires --kill and/or --net flag.
Workflow
- Read the project's package.json
- Identify all serve/dev commands (scripts that start local servers —
dev, serve, preview, start, etc.)
- Detect the port(s) used by each command
- Detect the framework (Next.js, Astro, Vite, etc.) from package.json dependencies
- Apply the requested tweaks
--kill flag
Add port-killing before serve commands so stale processes don't block startup.
Pattern
For each serve command, detect the port it uses and add a preXXX script that kills it:
"predev": "lsof -ti :PORT | xargs kill 2>/dev/null; true",
"dev": "astro dev",
- Use
preXXX npm lifecycle hook naming (e.g., predev for dev, preserve for serve)
- The kill command pattern:
lsof -ti :PORT | xargs kill 2>/dev/null; true
- If a
preXXX script already exists, prepend the kill command to it
- If the port is not obvious from the command, check common framework defaults (Astro: 4321, Next.js: 3000, Vite: 5173, etc.)
Port detection priority
- Explicit
-p PORT or --port PORT flag in the command
- Framework default port from dependencies
--net flag
Create :net suffixed variants of serve commands that bind to 0.0.0.0 for LAN access.
Pattern
For each serve command, create a COMMAND:net variant:
"dev": "astro dev",
"dev:net": "astro dev --host 0.0.0.0",
Framework-specific host flags
| Framework |
Flag |
| Astro |
--host 0.0.0.0 |
| Next.js |
-H 0.0.0.0 |
| Vite / Vitest |
--host 0.0.0.0 |
| Webpack Dev Server |
--host 0.0.0.0 |
| serve (npm) |
-l tcp://0.0.0.0:PORT or --listen tcp://0.0.0.0:PORT |
| http-server |
-a 0.0.0.0 |
| Docusaurus |
--host 0.0.0.0 |
- Place the
:net variant immediately after the original command
- If the command already has a host flag, replace it with
0.0.0.0
- If
--kill is also specified, the :net variant should also get a matching preXXX:net kill script
Both flags together
When both --kill and --net are specified, apply both tweaks. Example result:
"predev": "lsof -ti :4321 | xargs kill 2>/dev/null; true",
"dev": "astro dev",
"predev:net": "lsof -ti :4321 | xargs kill 2>/dev/null; true",
"dev:net": "astro dev --host 0.0.0.0",
Important
- Only modify scripts that actually start servers (dev, serve, preview, start and their variants)
- Do not touch build, test, lint, or other non-server scripts
- Preserve existing script order — insert new scripts adjacent to their originals
- If the argument is missing or invalid, ask the user which flag(s) to apply
1---2name: dev-tweak-serve-package-json3description: Tweak serve/dev commands in package.json. Use when: (1) User says 'tweak serve', 'dev tweak serve', or 'tweak-serve', (2) User wants to add port-kill before dev/serve (--kill), (3) User wants :net LAN-accessible variants of dev/serve (--net). Flags: --kill adds predev port cleanup, --net adds 0.0.0.0 host variants.4---56# dev-tweak-serve-package-json78Tweak serving-related commands in package.json. Requires `--kill` and/or `--net` flag.910## Workflow11121. Read the project's package.json132. Identify all serve/dev commands (scripts that start local servers — `dev`, `serve`, `preview`, `start`, etc.)143. Detect the port(s) used by each command154. Detect the framework (Next.js, Astro, Vite, etc.) from package.json dependencies165. Apply the requested tweaks1718## `--kill` flag1920Add port-killing before serve commands so stale processes don't block startup.2122### Pattern2324For each serve command, detect the port it uses and add a `preXXX` script that kills it:2526```json27"predev": "lsof -ti :PORT | xargs kill 2>/dev/null; true",28"dev": "astro dev",29```3031- Use `preXXX` npm lifecycle hook naming (e.g., `predev` for `dev`, `preserve` for `serve`)32- The kill command pattern: `lsof -ti :PORT | xargs kill 2>/dev/null; true`33- If a `preXXX` script already exists, prepend the kill command to it34- If the port is not obvious from the command, check common framework defaults (Astro: 4321, Next.js: 3000, Vite: 5173, etc.)3536### Port detection priority37381. Explicit `-p PORT` or `--port PORT` flag in the command392. Framework default port from dependencies4041## `--net` flag4243Create `:net` suffixed variants of serve commands that bind to `0.0.0.0` for LAN access.4445### Pattern4647For each serve command, create a `COMMAND:net` variant:4849```json50"dev": "astro dev",51"dev:net": "astro dev --host 0.0.0.0",52```5354### Framework-specific host flags5556| Framework | Flag |57| --- | --- |58| Astro | `--host 0.0.0.0` |59| Next.js | `-H 0.0.0.0` |60| Vite / Vitest | `--host 0.0.0.0` |61| Webpack Dev Server | `--host 0.0.0.0` |62| serve (npm) | `-l tcp://0.0.0.0:PORT` or `--listen tcp://0.0.0.0:PORT` |63| http-server | `-a 0.0.0.0` |64| Docusaurus | `--host 0.0.0.0` |6566- Place the `:net` variant immediately after the original command67- If the command already has a host flag, replace it with `0.0.0.0`68- If `--kill` is also specified, the `:net` variant should also get a matching `preXXX:net` kill script6970## Both flags together7172When both `--kill` and `--net` are specified, apply both tweaks. Example result:7374```json75"predev": "lsof -ti :4321 | xargs kill 2>/dev/null; true",76"dev": "astro dev",77"predev:net": "lsof -ti :4321 | xargs kill 2>/dev/null; true",78"dev:net": "astro dev --host 0.0.0.0",79```8081## Important8283- Only modify scripts that actually start servers (dev, serve, preview, start and their variants)84- Do not touch build, test, lint, or other non-server scripts85- Preserve existing script order — insert new scripts adjacent to their originals86- If the argument is missing or invalid, ask the user which flag(s) to apply