Laravel Chisel은 Laravel 스타터 킷에서 불필요한 기능을 제거하기 위한 포스트 인스톨 스크립트를 구축하기 위한 프리미티브를 제공하는 패키지입니다.스타터 킷에는 많은 기능이 미리 포함되어 있지만, 프로젝트에 따라서는 일부 기능이 불필요한 경우가 있습니다. Chisel은 이 문제를, 설치 후에 대화형으로 “필요한 기능만 남기는” 구조를 제공함으로써 해결합니다.
Chisel을 사용하는 스타터 킷은 프로젝트 루트에 chisel.php 파일을 배치합니다. 이 파일이 “어떤 기능을 옵션으로 할지”를 정의합니다.
<?phprequire getenv('LARAVEL_INSTALLER_AUTOLOADER');use Laravel\Chisel\Chisel;use Laravel\Chisel\Question;return Chisel::script(dirname(__DIR__)) ->questions([ Question::multiselect( name: 'auth_features', label: 'Which authentication features would you like to enable?', options: [ 'email-verification' => 'Email verification', ], hint: 'Use space to select, enter to confirm.', ), ]) ->selected('auth_features', 'email-verification', then: function (Chisel $c) { // 선택된 경우: 섹션 마커를 제거하고 코드는 남긴다 $c->files( 'resources/js/pages/settings/profile.tsx', 'app/Providers/FortifyServiceProvider.php', )->removeSectionMarkers('email-verification'); }, else: function (Chisel $c) { // 선택되지 않은 경우: 관련 파일과 기능을 삭제 $c->php('app/Models/User.php') ->removeImport('Illuminate\Contracts\Auth\MustVerifyEmail') ->removeInterface('MustVerifyEmail'); $c->file('config/fortify.php')->removeLinesContaining('Features::emailVerification()'); $c->files( 'app/Providers/FortifyServiceProvider.php', 'resources/js/pages/settings/profile.tsx', )->removeSection('email-verification'); $c->files( 'resources/js/components/email-verification-notice.tsx', 'resources/js/pages/auth/verify-email.tsx', 'tests/Feature/Auth/EmailVerificationTest.php', 'tests/Feature/Auth/VerificationNotificationTest.php', )->delete(); }, );
collectAnswers()는 응답 컬렉터를 반환합니다. 모든 메서드는 플루언트하며 임의의 순서로 호출할 수 있습니다. 비대화형 환경에서는 기본값이 자동으로 사용됩니다.외부의 Artisan 명령이 Laravel Prompts를 사용하여 프롬프트를 표시하고, 응답을 Chisel에 전달합니다.