Laravel 教程

Exclude Vendor and Default Commands in `php artisan dev`

发布
Exclude Vendor and Default Commands in `php artisan dev` image

php artisan dev command starts your development processes in one command. Those processes include framework defaults, vendor packages via a service provider, and the application.

Laravel 13.30 , we get two new methods for the DevCommands class, which allow you to opt out of vendor and default commands:

使用 Illuminate\Foundation\DevCommands ;
DevCommands :: withoutVendorCommands ();
DevCommands :: withoutDefaultCommands ();

This gives you complete control over what runs and locks everything down to whatever you define:

命名空间 应用程序\提供商 ;
使用 Illuminate\Foundation\DevCommands ;
使用 Illuminate\支持\服务提供商 ;
班级 应用服务提供商 延伸 服务提供者
{
民众 功能 引导 () : 空白
{
DevCommands :: withoutVendorCommands ();
DevCommands :: withoutDefaultCommands ();
DevCommands :: 工匠 'serve' , 'server' (英文):
DevCommands :: 工匠 'queue:work --queue=notifications' , 'queue:notifications' (英文):
DevCommands :: 节点 'dev' , '迅速地' (英文):
}
}

You can also get more granular, using only()except() . Let's say that you don't want to allow 任何 vendor commands, but you want everything from the framework except logs:

DevCommands :: withoutVendorCommands ();
DevCommands :: 除了 'logs' (英文):

Default Commands

The default commands come from the framework's registerDefaults() and registers four processes at the time of writing:

  • server
  • queue
  • logs (when pcntl_fork() exists)
  • vite , (when the project has a package.json

Checking the List

If you want to see which processes will run, you can use the dev:list 命令:

php artisan dev:list
server php artisan serve .................................. Illuminate\Foundation\Providers\ArtisanServiceProvider@boot
queue php artisan queue:listen --tries=1 --timeout=0 ..... Illuminate\Foundation\Providers\ArtisanServiceProvider@boot
logs php artisan pail --timeout=0 ....................... Illuminate\Foundation\Providers\ArtisanServiceProvider@boot
vite npm run dev ........................................ Illuminate\Foundation\Providers\ArtisanServiceProvider@boot

使用 --json flag gives you JSON output, which could be helpful for agents:

php artisan dev:list --json | jq
[
{
"command": "php artisan serve",
"name": "server",
"color": "#93c5fd",
"source": "Illuminate\\Foundation\\Providers\\ArtisanServiceProvider@boot",
"priority": 0
},
{
"command": "php artisan queue:listen --tries=1 --timeout=0",
"name": "queue",
"color": "#c4b5fd",
"source": "Illuminate\\Foundation\\Providers\\ArtisanServiceProvider@boot",
"priority": 0
},
{
"command": "php artisan pail --timeout=0",
"name": "logs",
"color": "#fb7185",
"source": "Illuminate\\Foundation\\Providers\\ArtisanServiceProvider@boot",
"priority": 0
},
{
"command": "npm run dev",
"name": "vite",
"color": "#fdba74",
"source": "Illuminate\\Foundation\\Providers\\ArtisanServiceProvider@boot",
"priority": 0
}

To learn more, check out the Artisan Dev Command docs . Opting out of default and vendor dev commands was contributed by 杰克·贝利斯#61344 and part of the Laravel 13.30 release.

保罗·雷德蒙德照片

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

赞助

laravelcloud logo
Laravel 云

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

访问 Laravel Cloud
Taylor disabled GitHub Issues on most Laravel open-source packages. image

Taylor disabled GitHub Issues on most Laravel open-source packages.

阅读文章
The Laracon Archive image

The Laracon Archive

阅读文章
Group Adjacent Collection Items in Laravel with chunkBy() image

Group Adjacent Collection Items in Laravel with chunkBy()

阅读文章
Laravel queue:work Now Prints Why the Worker Stopped image

Laravel queue:work Now Prints Why the Worker Stopped

阅读文章
Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites image

Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites

阅读文章
Collections chunkBy() and Storage Path Hardening in Laravel 13.30 image

Collections chunkBy() and Storage Path Hardening in Laravel 13.30

阅读文章