Suppressing console.log messages in production deployment



I seem to remember seeing somewhere, that it is possible to suppress console.log messages in production deployment by putting some special comments around them in the JS. These console.log expressions are then removed by StealJS during compilation. I’ve searched but I can no longer find any reference to how this works - maybe I’m just imagining things?

BTW - the migration from Can3 to Can4 has gone really well - we are now back at the bleeding edge of technology!



Hi @robfoweraker,

There are a few options for doing this.

You can use the envify build option and wrap your console statements like this:

if (process.env.NODE_ENV !== "production") {
  console.log("will only log in development");

Steal also allows you to remove code wrapped in steal-specific comments like these:

console.log("will only log in development");

when you set the removeDevelopmentCode build option.

Lastly, you can use the can-log/dev package, which has the same methods as console, but takes care of removing the logs in production mode.

Glad to hear your migration went well!

– Kevin


Hi Kevin,

Thanks for the answers. There are just too many options, I need to think about it now :wink:



Personally, I would go with the process.env.NODE_ENV option. This is the standard that is supported in Node and most module loaders.