PDA

View Full Version : Can you strip debugging code in production build?



eddyystop
2 Mar 2012, 5:51 AM
I have a fair amount of debugging code. They are function calls often with longish strings as parameters.

Is there a way I can design them so they can be stripped from the production build?

I'm new to ExtJS and haven't found info on this. I was assuming my build would contain something like:

sencha build -p app.jsb3 -d .

Thanks.

burnnat
2 Mar 2012, 6:20 AM
You sure can! If you look through the ExtJS source code, you'll often see code wrapped with comments like this:

//<debug>
if (!superclass) {
Ext.Error.raise({
sourceClass: 'Ext',
sourceMethod: 'extend',
msg: 'Attempting to extend from a class which has not been loaded on the page.'
});
}
//</debug>

Those "//<debug>" comments are there for exactly this purpose, to identify debugging code that can be stripped from the production build. All you have to do is set up your jsb3 file appropriately. For example, this will create a build with all the debug code left in:

{
"projectName": "Test Project",
"licenseText": "Copyright(c) 2012",
"builds": [
{
"name": "Test",
"target": "test-debug.js",
"options": {
"debug": true
},
"files": [
{
"path": "./",
"name": "test.js"
}
]
}
],
"resources": []
}

To strip out the debug code, all you have to do is set the "debug" value to false and rebuild.

eddyystop
2 Mar 2012, 6:42 AM
Great! Thanks.