Webpack 加载器 vs 插件;有什么不同? [英] Webpack loaders vs plugins; what's the difference?

查看:60
本文介绍了Webpack 加载器 vs 插件;有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

webpack 中的加载器和插件有什么区别?

What is the difference between loaders and plugins in webpack?

插件文档只是说:

使用插件添加通常与 webpack 中的包相关的功能.

Use plugins to add functionality typically related to bundles in webpack.

我知道 babel 使用加载器进行 jsx/es2015 转换,但看起来其他常见任务(例如 copy-webpack-plugin)使用插件代替.

I know that babel uses a loader for jsx/es2015 transforms, but it looks like other common tasks (copy-webpack-plugin, for example) use plugins instead.

推荐答案

当您使用诸如 require("my-loader!./my-awesome-模块") 在您的代码中.与插件相比,它们非常简单,因为它们 (a) 只向 webpack 公开一个函数,并且 (b) 无法影响实际的构建过程.

Loaders do the pre-processing transformation of virtually any file format when you use sth like require("my-loader!./my-awesome-module") in your code. Compared to plugins, they are quite simple as they (a) expose only one single function to webpack and (b) are not able to influence the actual build process.

另一方面,插件可以深度集成到 webpack 中,因为它们可以在 webpack 构建系统中注册钩子并访问(和修改)编译器、它的工作原理以及编译.因此,它们更强大,但也更难维护.

Plugins on the other hand can deeply integrate into webpack because they can register hooks within webpacks build system and access (and modify) the compiler, and how it works, as well as the compilation. Therefore, they are more powerful, but also harder to maintain.

这篇关于Webpack 加载器 vs 插件;有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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