Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate and minify cordova/phonegap plugin files

I'm building a Cordova 3.5.0 application. I use grunt to build a minified web app, then I use cordova CLI and cordova hooks to build a platform specific package. I use more than 10 different plugins, some Cordova official ones and some custom. I'm wondering how to concatenate and minify the JS files from the plugins with my other 3rd party libraries.

After executing cordova prepare I see a generated cordova_plugins.js file with the following content:

cordova.define('cordova/plugin_list', function(require, exports, module) { module.exports = [     {         "file": "plugins/org.apache.cordova.globalization/www/GlobalizationError.js",         "id": "org.apache.cordova.globalization.GlobalizationError",         "clobbers": [             "window.GlobalizationError"         ]     },     {         "file": "plugins/org.apache.cordova.globalization/www/globalization.js",         "id": "org.apache.cordova.globalization.globalization",         "clobbers": [             "navigator.globalization"         ]     } ]; module.exports.metadata =  // TOP OF METADATA {     "org.apache.cordova.globalization": "0.3.1" } // BOTTOM OF METADATA }); 

I know how to minify and generate a single file with these plugins but not how to tweak the cordova build process to get all clobbers from a single file but different packages. My first thought is all the process has to be accomplished in an AFTER_PREPARE step, inside the platforms/<platform>/assets/www folder

like image 567
sgimeno Avatar asked Sep 26 '14 10:09

sgimeno


1 Answers

Minification does improve performance for two reasons:

Reduced file-size (because it removes comments and unnecessary white-spaces), so your script loads faster. Even if it is embedded into the .

It is parsed faster, since comments and white-spaces don't have to explicitly ignored (since they're not there).

BUT, it is only going to make a real difference if the file is big (2000 lines or more), like jquery. There is no point minifying a 20 line file.

like image 130
Shaunak Avatar answered Oct 14 '22 17:10

Shaunak