Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Removing code for production
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tim Meadowcroft  
View profile  
 More options May 9 2012, 1:42 pm
From: Tim Meadowcroft <meer...@gmail.com>
Date: Wed, 9 May 2012 10:42:33 -0700 (PDT)
Local: Wed, May 9 2012 1:42 pm
Subject: Re: Removing code for production

On Sunday, 8 April 2012 19:07:11 UTC+1, Tauren Mills wrote:

> I'd like to remove some code for production and think UglifyJS is the tool
> for the job. Before I begin to tackle this, can anyone confirm that Uglify
> can be used to solve the problem described below?  I'd really appreciate it
> if someone could point me to any examples that do this or would give some
> suggestions on how to get started.

I added a feature to uglifyjs for precisely this sort of "production" use -
in this way I use uglifyjs in a way similar to the C preprocessor to
entirely remove code blocks by telling uglifyjs it should consider certain
symbols to have specific defined values, and then using the inherent "dead
code removal" feature.

  https://github.com/mishoo/UglifyJS#use-as-a-code-pre-processor

In particular, my "un-uglified code" includes

 if (typeof DEVELOPMENT === "undefined") DEVELOPMENT = true;
 if (typeof PRODUCTION === "undefined") PRODUCTION = false;

This way, in development, I can have things like

  if (DEVELOPMENT) {
    Logger.configure([
    {context: 'nike.profile.core.Application', level: Logger.LOG, save:
true},
    {context: 'nike.profile.models.Account', level: Logger.WARN, save:
true},
    {context: 'nike.profile.models.User', level: Logger.INFO, save: true}
    ]);
  }

and then, when I uglify my code with command lines args "--define
PRODUCTION=true --define DEVELOPMENT=false" (in addition to any others)
then the entire block will be removed (including the 'if' test itself).

I don't really need both symbols, but it sometimes makes my intent clearer.

I also use this for setting certain flags or initialising values in
debug/production mode etc

Cheers

--
Tim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.