问题描述
我试图从 freecodecmap 的这个视频中获取 webpack
I was trying to pick up webpack from this video from freecodecmap
https://www.youtube.com/watch?v=MpGLUVbqoYQ&t=396s
在视频的开头,讲师说我们需要 webpack 来管理依赖项,否则我们需要添加 <script>
标签,特别是为了让拆分的 JavaScript 模块工作.
at the beginning of the video the instructor says that we need webpack to manage dependencies otherwise we need to add <script>
tags in particular order for out split JavaScript modules to work.
但是如果我们将脚本标签设置为<script type="module">
,浏览器会加载所有使用
But if we set the the script tag to <script type="module">
, the browser load all the modules that are imported using
import {module_name} from "./module_loaction"
所以我发现很难理解 webpack 在 2021 年的用途.
so i am finding it difficult to understand what is the use of webpack in 2021.
推荐答案
为此使用 webpack 或任何其他捆绑工具有很多原因.
There are quite a few reasons for using webpack or any other bundling tool for that matter.
- 它允许您从 node_modules 导入包,而无需指定整个相对路径.查看答案:https://stackoverflow.com/a/52558858/6080889
- 它将文件捆绑在一个脚本中,而不是通过网络进行多次调用.
- 有一些插件可以缩小和压缩文件以减小捆绑脚本的大小.
- Webpack 甚至可以为您处理循环依赖.
如果您不需要上述任何功能以及捆绑程序提供的许多其他较小的功能,那么您就不需要它.
If you don't need any of the above mentioned feautres and many other smaller features provided by bundlers then you don't need it.
这篇关于为什么我们在 2021 年需要 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!