Using the latest version of Microsoft.AspNet.Web.Optimization v1.1.3
I am unable to get bundling to minify the JavaScript if it includes template literals. For example if I include the following in one of my bundle scripts:
var name = 'Bob';
var formattedName = `${name} says hello`;
The resulting bundle will join all files but it won't minify code, and gives me this error:
/* Minification failed. Returning unminified contents.
(2,13-14): run-time error JS1014: Invalid character: `
(2,15-16): run-time error JS1004: Expected ';': {
(2,30-31): run-time error JS1014: Invalid character: `
(3,1-2): run-time error JS1107: Expecting more source characters
*/
I understand this feature was only introduced in ECMAScript2015 and it's clearly not supported but is there a clean workaround other than reverting back to the old string concatenation methods?
var name = 'Bob';
var formattedName = name + ' says hello';
Also, will template literal support go into future versions of Microsoft.AspNet.Web.Optimization
?
I am using the bundleconfig.json method for minifying some script files and I encountered similar errors when running the appropriate task:
Illegal assignment: =
Expected ';'
Expected ';'
Expected expression
Expected '}'
I managed to change the literal from this:
style.textContent = `
...
`;
To this:
style.textContent = `
...`;
It will probably not answer your specific question (as you used Gulp), but might help someone out there, that doesn't want to start using npm's various packages for the same objective.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With