Microsoft.AspNet.Web.Optimization JavaScript捆绑无法最小化模板文字 [英] Microsoft.AspNet.Web.Optimization JavaScript bundling fails to minify template literals

查看:65
本文介绍了Microsoft.AspNet.Web.Optimization JavaScript捆绑无法最小化模板文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新版本 Microsoft.AspNet.Web.Optimization v1.1.3 如果包含模板文字。例如,如果我在捆绑脚本之一中包含以下内容:

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
*/

我知道此功能仅在ECMAScript2015中引入,显然不支持此功能,但是除了恢复到该功能之外,还有其他解决方法

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';

此外,模板文字支持将用于将来的 Microsoft.AspNet版本。 Web.Optimization

Also, will template literal support go into future versions of Microsoft.AspNet.Web.Optimization?

推荐答案

我正在使用 bundleconfig.json 方法,用于缩小一些脚本文件和运行适当的任务时遇到类似的错误:

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 '}'

我设法更改文字:

style.textContent = `
...
`;

到此:

style.textContent = `
...`;

它可能不会回答您的特定问题(使用Gulp时),但可能会帮助某个人,那是不想开始将npm的各种软件包用于同一目标。

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.

这篇关于Microsoft.AspNet.Web.Optimization JavaScript捆绑无法最小化模板文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆