rossmartin / cordova-uglify

Cordova hook that allows you to uglify or minify your apps JavaScript and CSS.
MIT License
116 stars 46 forks source link

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

Open luigi37 opened 6 years ago

luigi37 commented 6 years ago

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

rossmartin commented 6 years ago

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

luigi37 commented 6 years ago

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