Home » Android » javascript – Concatenate and minify cordova/phonegap plugin files

javascript – Concatenate and minify cordova/phonegap plugin files

Posted by: admin April 23, 2020 Leave a comment


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": [
        "file": "plugins/org.apache.cordova.globalization/www/globalization.js",
        "id": "org.apache.cordova.globalization.globalization",
        "clobbers": [
module.exports.metadata = 
    "org.apache.cordova.globalization": "0.3.1"

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

How to&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.