[Packaging] code pre-processor

49 views
Skip to first unread message

Mathieu Civel

unread,
Apr 26, 2012, 10:19:52 AM4/26/12
to socket...@googlegroups.com
Hello,

I used to write "dev only" code in previous projects. In JavascriptMVC it is possible to wrap lines with comments like 

//@DEV
code skipped in production
//@END-DEV

Which is quite handy for cleaning log infos or local configurations.
In HTML5Boilerplate, console.log statements are automatically skipped with the ant build task.

UglifyJs allow do define symbols (with --define) in order to do something approaching.

Is there a way to achieve this behavior at this moment ?
Or is there a way to hook the packaging method ? 

Thanks.

Owen B

unread,
May 1, 2012, 1:21:09 PM5/1/12
to socket...@googlegroups.com
Hi Mathieu

Good idea. I've looked into the Uglify code... it is possible to do this using the 'defines' option as you say but the implementation is a little... well, ugly.

You basically have to check for the existence of a global variable - which feels a bit messy.

I will keep thinking about this - hopefully we can find a better/cleaner idea.

Owen

Mathieu Civel

unread,
May 4, 2012, 4:37:01 AM5/4/12
to socket...@googlegroups.com
I'm glad you'll consider that. I didn't feel bad about adding a global in dev code as statements using them will be erased on production but I get your point.

David Rosen

unread,
May 4, 2012, 3:20:04 PM5/4/12
to socket...@googlegroups.com

Out of curiosity, I tested "define" in UglifyJS using the following code:

if (dev) alert('hi');

uglifyjs --define dev=false test.js

;

uglifyjs --define dev=true test.js

alert("hi");

So in both cases, the "if (dev)" gets optimized away.

Dave
Reply all
Reply to author
Forward
0 new messages