If you want to achieve something similar to the #if directives from C #, then you will need to do something that imposes certain code when creating your application.
There are several plugins for this that you can use. There are some build plugins (see here and here ) that will separate the code that is in the comments like this during build:
removeMeInProduction();
However, using these plugins, you may be mistaken in writing test-code or end-test-code , forcing you to leave the test code in the production process. You will not get a compilation error.
Because of this, it is probably better to find a build plugin that breaks down a function based on its name (see here - unfortunately, t find a gulp plugin for this). So you could write something like this:
function ifNotProduction(func: () => void) { func(); }
Then use it:
ifNotProduction(() => { console.log("Only run when test."); });
And then tell the assembly script to prohibit the use of this function when it is not a production assembly.
All in all, your simple solution is simply checking boolean is enough.
source share