为什么我们在 2021 年需要 webpack [英] Why we need webpack in 2021

查看:54
本文介绍了为什么我们在 2021 年需要 webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 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.

  1. 它允许您从 node_modules 导入包,而无需指定整个相对路径.查看答案:https://stackoverflow.com/a/52558858/6080889
  2. 它将文件捆绑在一个脚本中,而不是通过网络进行多次调用.
  3. 有一些插件可以缩小和压缩文件以减小捆绑脚本的大小.
  4. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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