How to handle a large hook script?

Hello, I’d like to run a script when a specific page type is updated. The script I need to run requires calling a PHP library (via require), etc. It’s does a bunch of stuff. Dumping this script into the config file seems sloppy and it doesn’t seem to like the require bit either. Should I house this script in a snippet or is there some other method that’s preferred? Please advise.

'hooks' => [
    'page.update:after' => function($newPage, $oldPage){
      if($newPage->intendedTemplate() == "mytemplate"):
        
        // Do lots of stuff. Here though? 
      
      endif;
    }
  ]

You can put hooks into a plugin, there you can also require/load the library.

You can either simply require and external script, or use Kirby load() method, or autoload via Composer.

Thanks for the reply @pixelijn