cordova-uglify icon indicating copy to clipboard operation
cordova-uglify copied to clipboard

Possible improvements: save-license, do not uglify framework (, images)

Open luigi37 opened this issue 7 years ago • 2 comments

I modified the script to KEEP the license at the beginning of my code and exclude frameworks like jquery as they might have issues.

In declarations:

var saveLicense = require('uglify-save-license');

then in "compress" function

switch (ext) {
case '.js':
  
console.log('?? js file ' + file);
 if (file.indexOf("jquery")<=-1) {
   console.log('--------------------uglifying js file ' + file);
    res = ngAnnotate(String(fs.readFileSync(file)), {
        add: true
    });
    
    result = UglifyJS.minify(res.src, {
            compress: {
                "drop_console": true
            }, 
            output: {
                comments: saveLicense
            },
            //fromString: true //removed because incompatible with uglify-js3
        });
    fs.writeFileSync(file, result.code, 'utf8'); // overwrite the original unminified file
}
  break;

I think those two things are quite useful. I did not issue a pull request as the code (especially for skipping jquery) is quite poor...

Would be great if those two things could be implemented.

I found also code about image but I think those were yours original and for some reason got deleted?

Thanks

luigi37 avatar Feb 25 '18 08:02 luigi37

Hey sorry it’s taken awhile to get to this. I’ll add the uglify-save-license package and have it available as an option.

Did you experience issues with uglify running against frameworks? I’ve never had any issues before.

If you need to exclude frameworks one easy way is to put them in their own folder and not have the hook configured to run against files in it, ex. www/lib/js

Thanks

rossmartin avatar Mar 03 '18 20:03 rossmartin

Hi Ross, no problem at all. Thanks for save license More than problem with Frameworks is problem with already minified frameworks... So you suggest to exclude directories? Thanks Luigi

luigi37 avatar Mar 03 '18 20:03 luigi37