消息

Laravel artisan dev:运行服务器、队列、日志和 Vite

发布 更新
Laravel artisan dev:运行服务器、队列、日志和 Vite 镜像

Laravel 13 introduced a new artisan dev command that standardizes everything you need to work on your project: the development server, a queue worker, log output, Vite, and more. Until recently, the skeleton wired those together with a dev script in composer.json that piped four commands through npx concurrently

Laravel 13.16 replaced it with a first-party command:

php 工匠 开发

composer dev script still exists in the skeleton, but it now does nothing except call php artisan dev . The process list moved into PHP, where you can register your own processes with the DevCommands 班级。

The Defaults

Out of the box the command runs four processes:

姓名 命令
server php artisan serve --host=localhost
queue php artisan queue:listen --tries=1 --timeout=0
logs php artisan pail --timeout=0
vite npm run dev

process is only registered when the pcntl_fork function is available, so Windows users get the other three. The vite process picks its prefix from whichever lockfile is in your project—npm, pnpm, Yarn, or Bun—so it runs pnpm run dev in a pnpm project without any configuration. Under the hood the command still shells out to concurrently , and since 13.18 it passes --kill-others-on-fail , so one process crashing stops the rest instead of leaving you with a half-running stack.

Registering Your Own Processes

Defaults cover a fresh install, but few applications stay that way for long. Consider an app that runs Horizon instead of queue:listen , broadcasts over 混响 , takes Stripe webhooks locally through the Stripe CLI, and type-checks TypeScript in watch mode. Register all of that in the boot 你的方法 AppServiceProvider :

命名空间 应用程序\提供商 ;
使用 Illuminate\Foundation\DevCommands ;
使用 Illuminate\支持\服务提供商 ;
班级 应用服务提供商 延伸 服务提供者
{
民众 功能 引导 () : 空白
{
如果 $this -> 应用程序 -> 环境 '当地的' )){
返回 ;
}
开发命令 :: 工匠 'horizon' , '队列' (英文):
开发命令 :: 工匠 'reverb:start --debug' , 混响 -> purple ();
开发命令 :: 登记
'stripe listen --forward-to' 配置 'app.url' '/stripe/webhook' ,
'条纹'
-> 橙子 ();
开发命令 :: nodeExec 'tsc --noEmit --watch --preserveWatchOutput' , 'types' -> 黄色的 ();
}
}

Four methods do the registering. The artisan() method prefixes the command with php artisan , node() prefixes it with the detected package manager's run command, nodeExec() uses the exec command ( npx and friends), and register() takes a raw shell command for anything else, like the Stripe CLI above.

The second argument is the process name shown in the terminal. Leave it off and the name is the first word of the command, which gives you horizon , reverb:start , 和 stripe . That first argument in the example is doing more than labeling, though: registering a process named queue replaces the default queue:listen worker with Horizon. Names are the identity of a process, so reusing one is how you swap or reconfigure a default:

开发命令 :: 工匠 'serve --host=localhost --port=9000' , 'server' (英文):

Registration order doesn't matter here. Commands registered from your application always outrank the framework defaults, and both outrank anything registered from vendor , so an installed package can't quietly take over a process you defined. Packages ship a method you call yourself instead of hooking in during discovery.

Colors are optional. Each process gets a distinct one automatically, and you only reach for blue() , purple() , pink() , orange() , green() , yellow() , 或者 color('#ff6347') when you want a specific process to stand out.

Checking and Filtering the List

To see what's registered without starting anything, run php artisan dev:list , added in 13.17. It prints each process, its command, and the file and line it was registered from—useful when a package's setup instructions added something you've forgotten about.

You can also trim the list without deleting registrations:

// Only run the server and vite processes...
开发命令 :: 仅有的 'server' , '迅速地' (英文):
// Run everything except the queue worker...
开发命令 :: 除了 '队列' (英文):

Both are filters applied at run time, so a process excluded by except() still shows up in your provider and can be brought back by deleting one line.

dev command was contributed by 乔·坦南鲍姆Pull Request #60412 , and the full details are in the Artisan documentation

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

归档于

赞助

Laravel Cloud 标志
Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

访问 Laravel Cloud
组合:多列上的精妙关系图

组合:多列上的精妙关系

阅读文章
MKSine:一款基于 Filament 的 CMS,支持插件、主题和模块(图片)

MKSine:一款基于 Filament 的内容管理系统,支持插件、主题和模块

阅读文章
在 Inertia.js v3.7 图片中取消飞行中表单提交

在 Inertia.js v3.7 中取消飞行中表单提交

阅读文章
Laravel Starter Kits 现在附带 Vite+ 图片

Laravel Starter Kits 现在随附 Vite+

阅读文章
Laravel Eloquent 中使用 refreshForUpdate() 实现悲观锁定 图片

Laravel Eloquent 中使用 refreshForUpdate() 实现悲观锁定

阅读文章
Laravel 异常消息中的掩码查询绑定图片

Laravel 异常消息中的查询绑定掩码

阅读文章