systemjs / builder

SystemJS build tool
MIT License
465 stars 122 forks source link

request for help #788

Open r3wt opened 7 years ago

r3wt commented 7 years ago

First of all, i don't understand what SystemJS is or why its designed the way it is. The concept of bundles and modules doesn't really make sense to me. When i think of a bundle, its a concat and minified collection of files, or rather all files in the project.

So in the context of SystemJS how would i bundle all modules in my project, including its dependencies, into a single bundle file? I'm not able to find anything in the documentation about this. i tried concating them but system still tries to load them with ajax, failing of course.

aluanhaddad commented 7 years ago

This is somewhat of an oversimplification (normalization, canonicalization, and evaluation omitted):

When an import is executed, the target module specifier is looked up in the registry.

If the registry has a value stored under that specifier then that value is returned.

If the registry does not have a value for that specifier then the module is loaded, perhaps via HTTP, and it is stored in the registry under the target module specifier.

By implication, a subsequent request for the same module will not cause it to be loaded a second time.

In an import of the form

import _ from 'lodash';

the module specifier is lodash.

The ES Module specification does not, as far as I know, account for bundles.

Bundles are deployment artifacts which are created to improve the startup time of web applications.

How do we create a bundle?

There's more than one way we might go about it but one way would be to create a script which causes the registry to be populated with the values of all the modules that will be needed by an application before that application runs.

In that sense a bundle is piece of code that has side effects.

When a bundle is executed it mutates the registry, storing the values corresponding to the bundled modules under their respective module specifiers in the registry.

You can use the systemjs-builder to create such a bundle.

Technologies such as the RequireJS optimizer, r.js, use an analogous approach.