Back-end developer is asking about front-end.
I've got two functions which are totally different. One of them is for a production, another - for a local development. For example, when I'm in a development mode, the situation is as follows:
/*
function f() {
// production logic
}
*/
function f() {
// development logic
}
As you may see, I always comment one of the functions. Before making a build for a production I should remove comments for the production function, and add them to the development one.
I really don't want to make the if
statement where I'll check out some variable (if the value equals "DEV"
then ... else ...). The functions are too large and contain many non-contiguous parts.
I googled a lot, but nothing has found. Is something like? Something like profiles with their variables that can be integrated into JS files? Or marking a function with a comment which excludes/includes a function from/in a build as that's possible with HTML.
The project is being gathered by Grunt.
As @dlsso mentioned in the comments, there is an effective
npm
plugin grunt-dev-prod-switch
to modify source files depending on the mode you are in.
Use to switch between previously defined block comment blocks in project files to change the environment from development to production and back.
After the configuration, it allows me to do the following:
/* env:prod */
function f() { ... }
/* env:prod:end */
/* env:dev */
function f() { ... }
/* env:dev:end */
The plugin determines which mode/environment is turn on (dev_prod_switch.options.environment
), analyses comments of the files (are defined in the dev_prod_switch.all.files
property) and spoils (comment) all blocks don't relate to the current mode.
For example, the production mode is turned on:
/* env:dev *#/
function f() { ... }
/* env:dev:end */