Skip to content

Use IS_MINIFIED to disable friendly debugger in minified builds #1329

Description

@toolness

Currently, the friendly debugger is disabled by overwriting all relevant private p5 methods (basically _validateParameters and _friendlyFileLoadError) in the footer of the minified build (done via the gruntfile configuration for uglify).

However, a disadvantage of this is that the code for the friendly debugger is still present in minified builds--it's just overwritten at run-time to be a no-op.

In #1318, I introduced a new uglifyJS-based global defined only in minified builds called IS_MINIFIED. If we use this variable anywhere in p5's source code like so:

if (typeof(IS_MINIFIED) === 'undefined') {
  // We're in an unminified build, do friendly debugging logic etc. here
} else {
  // We're in a minified build, probably just do nothing.
}

then uglifyJS will realize that the conditional evaluates to a constant and will remove the first branch when it generates the minified build. This is called "dead code removal" and it's nice because it means the minified build will really be as small as possible.

More background on how this works is explained here: #1318 (comment)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions