ajax minifier_ES6 JavaScript Minifier:babili

ajax minifier

The Babel toolchain is amazing.  We've used Babel to write ES6 JavaScript well before ES6 features hit browsers, we use it to parse JavaScript and write JSX, and much more.  Babel can do just about anything with the JavaScript language and I've just learned of another use for the Babel toolchain:  babili, the ES6+ aware JavaScript minifier.

Babel工具链很棒。 在ES6功能进入浏览器之前,我们已经使用Babel 编写了ES6 JavaScript ,我们使用它来解析JavaScript和编写JSX等。 Babel可以使用JavaScript语言执行几乎所有操作,而且我刚刚了解到Babel工具链的另一种用途: babili,这是支持ES6 +JavaScript minifier

At the time of its creation, many other JavaScript minifiers weren't capable of ES6 minifying but when you have an amazing, forward-thinking parser like Babel, creating an ES6+ aware minifier becomes much easier.

在创建它时,许多其他JavaScript压缩程序都无法进行ES6压缩,但是当您拥有像Babel这样令人惊叹的,具有前瞻性的解析器时,创建支持ES6 +的压缩程序将变得更加容易。

从命令行使用babili (Using babili from Command Line)

I prefer to use babili from command line when doing a quick minification:

快速缩小时,我更喜欢从命令行使用babili:


// Sample source code:
class Mangler {
  constructor(program) {
    this.program = program;
  }
}
new Mangler(); // without this it would just output nothing since Mangler isn't used

// Before:
// ES2015+ code -> Babel -> Babili/Uglify -> Minified ES5 Code
var a=function a(b){_classCallCheck(this,a),this.program=b};new a;

// After:
// ES2015+ code -> Babili -> Minified ES2015+ Code
class a{constructor(b){this.program=b}}new a;


Note that babili does not transpile ES5 JavaScript before minifying -- you'll need to use an excellent tool like lebab to get ES6+ from ES5.  Assuming you do have ES6 in your source file, you'll notice all of your code has been elegantly minified by babili!

需要注意的是巴比利 transpile ES5JavaScript涅槃之前-你需要使用像一个很好的工具lebab从ES5来获得ES6 +。 假设您的源文件中确实有ES6,您会发现babili巧妙地缩小了所有代码!

通过Node.js使用babili (Using babili via Node.js)

Being a JavaScript parser implemented in JavaScript, babili is also available for use via Node.js APIs.  There are also dozens of babili plugins you can use to customize your minification.  Check out the documentation for impressive benchmarks and Node.js usage information.

babili是用JavaScript实现JavaScript解析器,也可以通过Node.js API使用。 您还可以使用数十个babili插件来自定义缩小版本。 查阅文档以获取令人印象深刻的基准测试和Node.js使用信息。

Babel has had as much of an impact on writing JavaScript for the web as any popular JavaScript frameworks and will continue to do so in the future.  If you haven't explored the Babel toolchain and it's plethora of plugins, take the time to give them a look.  Being able to write and experiment with edge JavaScript language features before they hit the browsers is an advantage to any developer, whether it be in getting them a job or simply keeping them up to speed with the language.

Babel与任何流行JavaScript框架一样,对Web上JavaScript产生了很大的影响,并且将来会继续这样做。 如果您还没有探索Babel工具链,并且它有太多的插件,请花一些时间看看它们。 对于开发人员来说,能够在边缘JavaScript语言功能进入浏览器之前对其进行编写和试验是一个优势,无论是让他们找到一份工作,还是简单地使其与语言保持同步。

翻译自: https://davidwalsh.name/es6-minifier

ajax minifier

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值