jekyll-assets
jekyll-assets copied to clipboard
Uglifier/UglifyJS doesn't support modern ES6
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?
I'll save you some time :)
Add following in your _config.yml
:
jekyll-minifier:
uglifier_args:
harmony: true
@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