简体   繁体   English

ASP.NET Core BundleMinifier 在缩小后删除异步修饰符

[英]ASP.NET Core BundleMinifier removes async modifier after minification

I added bundleconfig.json to ASP.NET Core application.我将bundleconfig.json添加到 ASP.NET Core 应用程序。 It has the following structure:它具有以下结构:

[
  {
    "outputFileName": "wwwroot/js/main.min.js",
    "inputFiles": [
      "wwwroot/js/scripts/first.js",
      "wwwroot/js/scripts/second.js"
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }
]

Both scripts has been minified and merged into main.min.js .两个脚本都已缩小并合并到main.min.js But after minification all async modifiers has been removed from result script.但在缩小后,所有async修饰符都已从结果脚本中删除。

Function such as功能如

async function foo() {
  await /* some promise */;
}

have been turned into:已经变成:

function foo() {await /*some promise*/;}

How do I avoid removing async modifier?如何避免删除async修饰符?

I'v reproduced the issue and tried to minify a simple js file that using ES6 specifications and later.我重现了这个问题,并试图缩小一个使用ES6 specifications及更高版本的简单 js 文件。

Test.js测试.js

async function foo() {
    await bar();
}
async function bar() {
    for (var i = 0; i < 10; i++) { // do some work
    }
}

Then i tried to minify the file with Bundler and Minifier tool then this error thrown:然后我尝试使用Bundler 和 Minifier工具缩小文件,然后抛出此错误:

在此处输入图片说明

This means Bundler and Minifier doesn't support ES6 specifications and later.这意味着Bundler 和 Minifier 不支持 ES6 规范及更高版本。

For confirmation i started searching about this issue in the Github and i found these same behaviors为了确认,我开始在Github 中搜索这个问题,我发现了这些相同的行为

I can surely claim that this is The Transpilers Issue我可以肯定地说这是Transpilers问题

Transpilers, or source-to-source compilers, are tools that read source code written in one programming language, and produce the equivalent code in another language.转译器或源到源编译器是读取以一种编程语言编写的源代码并生成以另一种语言编写的等效代码的工具。

The most common and widely use one is TypeScript最常见和使用最广泛的一种是TypeScript

TypeScript in some cases Transpiles ES6 and later to ES5在某些情况下, TypeScript会将ES6及更高版本转换为ES5

For example: if you set Target to ES6 and ES2015 it Transpiles to ES5 .例如:如果您将 Target 设置为ES6ES2015它会转换为ES5 However, if You Target to ES2020 does NOT Transpile your code.但是,如果您的目标是ES2020则不会转译您的代码。

At The End在末尾

  • BundlerMinifier uses NUglify that perform javascript code minification So There is NO way minifying ES6 and later codes by using Bundler and Minifier. BundlerMinifier 使用 NUglify 来执行 javascript 代码缩小,所以没有办法通过使用 Bundler 和 Minifier 来缩小 ES6 和更高版本的代码。 Unless, The Author decides to support it.除非,作者决定支持它。
  • You are encountering The Transpile Issue (ex:ES6 to ES5).您遇到了 Transpile 问题(例如:ES6 到 ES5)。
  • Bundler & Minifier doesn't remove unknown keywords like async but thrown error Bundler & Minifier不会删除诸如async类的未知关键字,但会引发错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM