任务运行器(Gulp、Grunt 等)和捆绑器(Webpack、Browserify).为什么要一起使用? [英] Task Runners (Gulp, Grunt, etc) and Bundlers (Webpack, Browserify). Why use together?

查看:19
本文介绍了任务运行器(Gulp、Grunt 等)和捆绑器(Webpack、Browserify).为什么要一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对任务运行器和捆绑器世界有点陌生,并且在经历诸如

I am a bit new to the task runner and bundler world and while going through things like

Grunt、Gulp、Webpack、Browserify

Grunt, Gulp, Webpack, Browserify

,我不觉得他们之间有什么区别.换句话说,我觉得 Webpack 可以做任务运行器所做的一切.但是我仍然得到了一个巨大的例子,其中 gulp 和 webpack 一起使用.我不知道为什么.

, I did not feel that there is much difference between them. In other words, I feel Webpack can do everything that a task runner does. But still I got a huge examples where gulp and webpack are used together. I couldn't figure out the reason why.

对于这方面的新手,我可能会走错方向.如果您能指出我所缺少的,那就太好了.欢迎任何有用的链接.

Being new to this, I might be taking things in the wrong direction. It will be great if you could point out what I am missing. Any useful links are welcome.

提前致谢.

推荐答案

GruntGulp 实际上是任务运行器,它们具有配置驱动任务与基于流的转换之类的区别.每个都有自己的优点和缺点,但归根结底,它们几乎可以帮助您创建可以运行以解决更大的构建问题的任务.大多数时候,它们与应用程序的实际运行时间无关,而是它们转换或放置文件、配置和其他东西,以便运行时间按预期工作.有时它们甚至会生成运行应用所需的服务器或其他进程.

Grunt and Gulp are actually task runners, and they have differences like config driven tasks versus stream based transformations. Each has its own strengths and weaknesses, but at the end of the day, they pretty much help you create tasks that can be run to solve a larger build problem. Most of the time, they have nothing to do with the actual run-time of the app, but rather they transform or they put files, configs and other things in place so that the run time works as expected. Sometimes they even spawn servers or other processes that you need to run your app.

WebpackBrowserify 是包捆绑器.基本上,它们旨在运行包的所有依赖项,并将它们的源连接到一个文件中,(理想情况下)可以在浏览器中使用.它们对于现代 Web 开发很重要,因为我们使用了许多设计为与 Node.jsv8 编译器.同样,有些开发人员更喜欢其中一种(或有时两者兼有!),这也有优缺点和不同的原因.通常,这些解决方案的输出包包含某种引导机制,以帮助您在一个可能很大的包中找到正确的文件或模块.

Webpack and Browserify are package bundlers. Basically, they are designed to run through all of a package's dependencies and concatenate their source into one file that (ideally) can be used in a browser. They are important to modern web development, because we use so many libraries that are designed to run with Node.js and the v8 compiler. Again, there are pros and cons and different reasons some developers prefer one or the other (or sometimes both!). Usually the output bundles of these solutions contain some sort of bootstrapping mechanisms to help you get to the right file or module in a potentially huge bundle.

runner 和 bundler 之间的界限可能很模糊,因为 bundler 也可以在运行时进行复杂的转换或 trans-pilations,所以它们可以做一些任务运行者可以做的事情.事实上,在 browserify 和 webpack 之间可能有大约一百个 transformers 可以用来修改你的源代码.相比之下,npm 上至少列出了 2000 个 gulp 插件.因此,您可以看到对于最适合您的应用程序的方法有明确的定义(希望... ;)).

The blurred line between runners and bundlers might be that bundlers can also do complex transformations or trans-pilations during their run-time, so they can do several things that task runners can do. In fact, between browserify and webpack there's probably around a hundred transformers that you can use to modify your source code. For comparison, there's at least 2000 gulp plugins listed on npm right now. So you can see that there are clear (hopefully... ;)) definitions of what works best for your application.

话虽如此,您可能会看到一个复杂的项目实际上同时或串联使用任务运行器和包捆绑器.例如在我的办公室,我们使用 gulp 来启动我们的项目,而 webpack 实际上是从一个特定的 gulp 任务运行的,该任务创建了我们在浏览器中运行我们的应用程序所需的源包.因为我们的应用是同构,我们也捆绑部分服务器代码.

That being said, you might see a complex project actually using both task-runners and package bundlers at the same time or in tandem. For example at my office, we use gulp to start our project, and webpack is actually run from a specific gulp task that creates the source bundles that we need to run our app in the browser. And because our app is isomorphic, we also bundle some of the server code.

以我的拙见,您可能希望熟悉所有这些技术,因为您很可能会在您的职业生涯中看到(使用)所有这些技术.

In my humble opinion, you might want to get familiar with all of these technologies because chances are you will see (use) all them in the course of your career.

这篇关于任务运行器(Gulp、Grunt 等)和捆绑器(Webpack、Browserify).为什么要一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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