Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 5 Bundling and minification Javascript ES6

Minification fails when I try to use Ecmascript-6 features in my app.

If i try to use an arrow function:

$.get('/clients/all').done(response => {
  // Do something with the response
})
 

I get the following error:

/* Minification failed. Returning unminified contents.
(8,45-46): run-time error JS1195: Expected expression: >
(36,6-7): run-time error JS1195: Expected expression: )
(37,1-2): run-time error JS1002: Syntax error: }
 */

And so on with other ES6 features.

Do you know an ItemTransform for ES6?

like image 642
anyeloamt Avatar asked Jul 07 '17 17:07

anyeloamt


People also ask

How do you use bundling and minification in MVC 5?

Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".

Can we use bundling and minification with ASP NET web forms like MVC?

To optimize the performance of an application I found that bundling and minification can significantly improve the performance. It can be applied on MVC as well as in ASP.NET web forms.

What are the two types of bundles in MVC 5?

You can see ScriptBundle and StyleBundle objects we are using for bundling the js and CSS types of files. ScriptBundle: is responsible for Script files i.e javascript (JS). StyleBundle: is responsible for stylesheet files i.e CSS.

How bundling and minification works in MVC?

Bundling and Minification are two performance improvement techniques that improves the request load time of the application. Most of the current major browsers limit the number of simultaneous connections per hostname to six. It means that at a time, all the additional requests will be queued by the browser.


1 Answers

Still there is no .NET bundling package for ES6+.

But as a workaround you can use: babeljs.io > Try It Out > Presets: ES2015.

The following code:

var gridNames = Enumerable.From(verifiedKeys).Select(x => `demo_${x}`).ToArray();

Will be translated into:

var gridNames = Enumerable.From(verifiedKeys).Select(function (x) {
  return "demo_" + x;
}).ToArray();

Link: https://babeljs.io/repl and check: Presets > ES2015.

like image 69
Anton Lyhin Avatar answered Oct 18 '22 11:10

Anton Lyhin