I'm not sure how you define "debug" mode exactly, but if debug mode is more than just what scripts are compiled then I'd generally just conditionalize the function as you've done (I've worked on a number of JavaScript apps for example where we have had a "debug" mode even when the minified scripts were released to help with customer issues in production ... it was activated either through a cookie or a query string):
// this would be set for example to true when
// in debug mode
export var isDebugModeActive: boolean = false;
export var trap = () => {
debugger;
};
if (isDebugModeActive) {
// since you may not want to conditionalize
// through a #PRAGMA like system every call to
// trap, this just no-ops the function
trap = () => {};
}
// or
trap = () => {
// checking a boolean is going to be
// really fast ... :)
if (isDebugModeActive) {
debugger;
}
}
Having a "debug" mode works well when you want to infrequently, but sometimes output additional information to the browser console log for example.