How do I run a script before compiling a project?

Solution by example from another project that builds a website with npm before the build is started:

The script does not rely on any PreAction or anything, it just runs directly the function.