Open maxkfranz opened 5 years ago
@maxkfranz great tip. thanks.
@maxkfranz I implemented a simple version of your suggestion. Adequate? It avoids adding another npm module. Manipulation of development|production status is hard-coded, but perhaps not too awful.
var executionMode = "beta";
const log = function(msg)
{
if(executionMode == "devel")
console.log(msg);
}
If you're fine with hard-coding that value, that's fine. Otherwise it's best to use something like process.env.NODE_ENV === 'development'
with the webpack env plugin: https://webpack.js.org/plugins/environment-plugin/
NODE_ENV
is the standard environment variable, but you could use something different if that would integrate better with the other things you're building in your Makefile.
@maxkfranz I'll give it a try. webpack plugins are a little opaque to me at this point. Are these steps about right?
webpack.EnvironmentPlugin
~/github/cyjShiny/browserCode/makefile
) which sets and exports the bash environment variable NODE_ENV=development|prodlog
functionarguments
in your log
function, without obvious prior assignmentAm I close?
use npm to install webpack.EnvironmentPlugin
It should be built-in
configure webpack.config.js to load that plugin by adding it to the module.exports.plugins array
yes
create a make target (in ~/github/cyjShiny/browserCode/makefile) which sets and exports the bash environment variable NODE_ENV=development|prod
yes
that value controls the logic of the new log function
yes
I don't understand the use of arguments in your log function, without obvious prior assignment
arguments
is a keyword that can be used for variadic functions in js. It's an array-like object that contains all the arguments passed to the function. It's useful if your logging function accepts multiple arguments like console.log()
does, e.g. console.log('this is the value of foo', foo)
.
While useful for debugging, these should be removed at least in prod builds.
You can use NODE_ENV and the environment webpack plugin for this, e.g.
An approach like above should be used or the messages should be removed altogether.