如何在webpack 2和typescript和angular 2中使用摇树? [英] How to use tree-shaking with webpack 2 and typescript and angular 2?

查看:105
本文介绍了如何在webpack 2和typescript和angular 2中使用摇树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用角度设置了webpack 2,并且大多数情况下它似乎都可以工作.似乎它没有执行tree-shaking,因为我有一个几乎不执行任何操作的应用程序,并且vendor.js仍然是800+ KB.

I have set up webpack 2 with angular and mostly it seems to work. It does not seem though that it does the tree-shaking, since I have an app that does almost nothing, and the vendor.js is still 800+ KB.

似乎有关如何打开树状摇动的信息很少,但是据我了解,它对于ES6模块是自动打开的,但不适用于ES5.是这样吗?

It seems there is very little information available on how to turn the tree-shaking on, but what I understood that it's automatically turned on for ES6 modules, but does not work for ES5. Is that so?

最重要的是:如何使用webpack2对typescript/angular2应用摇树?

And most importantly: How can I apply tree-shaking to typescript/angular2 with webpack2?

推荐答案

我发现这非常好

I have found this very nice repository with examples on how to do this.

如此处以及对该问题的评论中所述,显然存在一些错误,这些错误阻止了摇树的发生.这似乎意味着现在真的无法使用"target": "es5".

As mentioned in there and in the comments to the question, there are apparently bugs that prevent the tree-shaking from happening. That seems to mean it's not really possible to do now with "target": "es5".

我们可以使用es2015,但是我们需要一些其他步骤(例如通过Babel)将其编译为es5,直到浏览器支持为止.

We can use es2015, but then we'll need some additional steps (e.g. via Babel) to compile to es5 until browsers support it.

这篇关于如何在webpack 2和typescript和angular 2中使用摇树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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