Is Webpack approach more optimized than RequireJs (or another AMD)?

127 Views Asked by At

I've got one theoretical question: I'm developing using by Angular2 and Webpack and it works fine for me. But the native Angular2 uses RequireJs (or another asynchronous module definition) to load additional js files on fly and on demand. But webpack gathers all files-modules in one file which load right when an application starts. And I thought that the "on demand" (asynchronous module definition) loading is more optimized than the webpack using. Could you help me to understand the webpack advantages in this case?

1

There are 1 best solutions below

0
On

But the native Angular2 uses RequireJs

It used to be System.js, but webpack is now part of angular cli.

But webpack gathers all files-modules in one file which load right when an application starts.

You can make several bundles too, you don't have to produce just one file. but it's true that webpack is not meant to be an asynchronous module loader.

And I thought that the "on demand" (asynchronous module definition) loading is more optimized than the webpack using.

Webpack does no loading on the fly but makes bundling easy. With angular 2 you don't have to worry about how you will load your modules because they can be lazy-loaded with the router, there are available configurations for both webpack and system.js.

So it's just a "matter of style" if you feel more comfortable with system.js, go for it, if you feel more comfortable with webpack, go for webpack or if you just don't care of the bundling system, go for angular-cli.