Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.AspNet.Web.Optimization JavaScript bundling fails to minify template literals

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?

like image 936
Stokedout Avatar asked Nov 09 '22 00:11

Stokedout


1 Answers

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.

like image 96
Artur Avatar answered Nov 14 '22 20:11

Artur