Angular2开发前端是否需要结合webpack?

    忘记从哪听到的声音:前端需要用上webpack、gulp,提高效率~~~

    既然有好的工具,我一定要去了解啊。于是开始查一些webpack、gulp的资料。有一些声音是:用了webpack基本上就不需要gulp了。so,我把精力主要放在webpack,先了解一个再说。

    首先webpack和gulp都是构建类工具。我们的前端框架采用的是Angular2。

    但在了解的过程中,我就纠结了......为啥咧:

    以webpack为例:


纠结一:为什么我要用wepack

    webpack核心是:1:一切皆模块。2、按需加载

    but:这些理念也在Angular2中已经体现的淋漓尽致了啊。首先Angular2就是模块化、组件化思想的产物。对于按需加载,Angualr2有套懒加载(lazyload)机制,就是要实现按需加载。


纠结二:为什么我要用wepack

扫描二维码关注公众号,回复: 11939091 查看本文章

    使用webpack需要进行一套配置文件的配置。从而实现自动构建,并且可以通过你的import依赖关系,最小化包——通过webpack命令

    but:我没用webpack,也是通过命令构建的捏,也可以实现最小化:ng build --prod --aot,并且我不需要任何配置,不需要考虑任何东西......

    .

    .

    .

    .

    .

    纠结了很多,也纠结了很久,总之在纠结:我为什么要用webpack,不用它我也很方便,都是通过命令实现。用了它,反而需要进行很多配置。

    沉心静气,思考:我用的命令来自哪?关于构建的命令我都是:ng **。而ng 是来自于搭建环境时候的angular-cli。(此刻应该有个小灯泡出现 )


    angular-cli是什么??

    于是查到了这句话:

What is Angular CLI?

AngularCLI is simply a command line interface that bundles some of the techniquesmentioned above. Like it helps you generate code, following the best practicesof the official Angular 2 StyleGuide.Under the hood it uses Webpack, to the exactlythe stuff we mentioned above (minify files, bundle them, etc..).The differenceis that you dont have to know Webpack, how it works and how it hasto be configured and set up. It will be done by the CLI for you, obviouslywithin the limits of it.


    看红色部分,看红色部分~~


    angular cli 底层奏是webpack。我为什么不需要配置,就能实现所有的构建呢:看绿色部分,看绿色部分。angular cli就是让你不需要知道什么是webpack,不需要考虑它是怎么工作的,不需要考虑如何配置。——纯傻瓜式!!!!


    再看一篇更全面的介绍:

Why should you use angular-cli?


总结:

    原来我所谓的没用webpack,其实都用了,只不过又被封装了一层~~~

    所以我们用angular2开发前端,还需要再加入webpack吗?








猜你喜欢

转载自blog.csdn.net/u012654963/article/details/74783647
今日推荐