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

Uglifier/UglifyJS doesn't support modern ES6 #654

Open
iamdriz opened this issue Dec 29, 2020 · 2 comments
Open

Uglifier/UglifyJS doesn't support modern ES6 #654

iamdriz opened this issue Dec 29, 2020 · 2 comments

Comments

@iamdriz
Copy link

iamdriz commented Dec 29, 2020

We use Jekyll Assets with great passion in our static sites but we've been getting continually frustrated with Uglifier not supporting ES6 syntax like below:

class ExampleClass {
    static get values() {
    }

    onBlur = (event) => {
    }
}

As it means we have to define them manually using defineProperty like so:

function _defineProperty(obj, key, value, accessor) {
    if (accessor == "getter") {
        Object.defineProperty(obj, key, {
            get: value,
            enumerable: true,
            configurable: true,
        });
    } else if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
// define a getter
_defineProperty(ExampleClass, 'values', () => {}, 'getter');
// define a method
class ExampleClass {
    constructor(...args) {
        super(...args);
            _defineProperty(this, "onBlur", event => {});
    }
}

I've raised this as an issue with UglifyJS but they don't seem to be doing a very good job of supporting the modern syntax...

How feasible is it to replace Uglifier with something more modern that understands ES6 syntax properly?

@Yankie
Copy link
Contributor

Yankie commented Mar 9, 2021

I'll save you some time :)
Add following in your _config.yml:

jekyll-minifier:
  uglifier_args:
    harmony: true

@iamdriz
Copy link
Author

iamdriz commented Mar 11, 2021

@Yankie Can you elaborate on what the above config does? We already have harmony: true in our _config.yml:

assets:
  source_maps: true # false on JEKYLL_ENV=production
  destination: "/assets"
  compression: true
  compressors:
    uglifier:
      comments: false
      harmony: true

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