I’m loading a javascript file (located in source/javascripts
) by using a helper method <%= javascript_include_tag "vanilla-tilt.js" %>
The desired effect is tilting of images, and it works great in my browser, everything seems to load and work fine.
When I try to build the site, however, I get a syntax error that appears related to the fact that the javascript is using a class. I pared the file down to the simplest structure to test this:
This version builds successfully:
const VanillaTilt = (function () {
'use strict';
return VanillaTilt;
}());
This version causes the build to fail with an error that says “Unexpected token: name (VanillaTilt)”
const VanillaTilt = (function () {
'use strict';
class VanillaTilt {}
return VanillaTilt;
}());
The only difference being the addition of class VanillaTilt{}
which is where all of the code for the desired effect lives.
I’m not a javascript expert, but I have looked into the syntax for creating classes and I can’t see anything that appears wrong.
Is there something inherent in Middleman that would cause this build to fail? I know that javascript classes aren’t supported on IE/Edge unless enabled by individual users, would that be something that Middleman is checking for and therefore throwing a syntax error?