8

I was trying to pick up webpack from this video from freecodecmap

https://www.youtube.com/watch?v=MpGLUVbqoYQ&t=396s

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.

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"

so i am finding it difficult to understand what is the use of webpack in 2021.

Nibir Ray
  • 101
  • 4

1 Answers1

4

There are quite a few reasons for using webpack or any other bundling tool for that matter.

  1. It lets you import packages from node_modules without having to specify the entire relative path. See answer: https://stackoverflow.com/a/52558858/6080889
  2. It bundles the file in a single script instead of making multiple calls over the network.
  3. There are plugins to minify and compress the files to make the bundled script size small.
  4. Webpack even handles circular dependencies for you.

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.

dRoyson
  • 1,466
  • 3
  • 14
  • 25
  • 3
    Interestingly, #2 is not necessarily a benefit any more. With HTTP/2 making concurrent requests, more requests can actually be quicker (Though if you are minifying, the extra compression from bundling can certainly counteract that) – DBS Apr 23 '21 at 14:23