Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uglify JS files reduced to 'undefined' #46

Open
rolinger opened this issue Oct 1, 2018 · 5 comments
Open

uglify JS files reduced to 'undefined' #46

rolinger opened this issue Oct 1, 2018 · 5 comments

Comments

@rolinger
Copy link

rolinger commented Oct 1, 2018

I know this there is an open issue on this thread already, however, most of the info on that thread is about deploying from a windows machine.

I am having problems with 'cordova-uglify' on my windows machine deploying my project for Android, but now I am having the same problem on my mac deploying for iOS.

The current version of cordova-uglify is causing 3 files on my windows -> android deploying to be undefined, and 9 files on my mac->iOS to be undefined. Can't use this plugin anywhere.

@rodrigograca31
Copy link

I was adding the plugins folder to be compressed and started facing the same issue and I'm not on Windows like you @rolinger

one of the plugins JavaScript file is turned into "undefined":
This file from this plugin to be more precise:
https://github.com/pushandplay/cordova-plugin-apprate/blob/master/www/AppRate.js

@rodrigograca31
Copy link

Ok, I tracked it down:

As stated in uglify-js:

* uglify-js only supports JavaScript (ECMAScript 5).
* To minify ECMAScript 2015 or above, transpile using tools like Babel.

The file I mentioned above uses const in which is part of ES6.
I found it out trying to uglify this file directly and getting the following output:

Parse error at AppRate.js:300,2
  const dateTimestamp = date.getTime();
  ^
ERROR: Unexpected token: keyword «const»

After changing const to var and uglifying again it works.

@rolinger
Copy link
Author

Is there any kind of parser that error checks before attempting to uglify? When I did this time it royally hosed my entire project. I couldn't undo things and I basically had to reinstall my entire project from scratch. I have avoided it since because of this...though I want minify and uglify applied to my project, I can't do it until I know what in my project is breaking things.

@rodrigograca31
Copy link

@rolinger yes there is.

I used es-check: https://github.com/dollarshaveclub/es-check

If anyone has time this package could be used to check the files before uglifying until we have ES6 support...

also, IDK how you hosed your project but I was also messing with some files earlier and kinda doing the same so here goes 2 tips:

  1. remove and re-add the platform, this should "re-copy" all the files cordova platform rm android && cordova platform add android
  2. After using this plugin go to "PROJECT/platforms/android/app/src/main/assets/www" and use your file browser to filter by .js then order them by size and the undefined ones should be the smallest with 9 bytes only....

@rodrigograca31
Copy link

coming back to this. uglify-js doesn't support ES6.

I'm now using Terser 5 as an alternative. outputs a few errors but works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants