Add optional callback for `once` compilation

Allow setting a callback (second argument to middleware) which is executed on `once` compilation, to facilitate automated testing of compilation configuration.