flaviait / ng2-jspm-template

A template for a quick development workflow with angular 2 and jspm
MIT License
14 stars 3 forks source link

Add a "simple" lazy loading example #38

Open DorianGrey opened 7 years ago

DorianGrey commented 7 years ago

... ok, the example itself is simple, but the way to support lazy loading wasn't.

Some things to note:

@svi3c, have fun with reviewing 😄

DorianGrey commented 7 years ago

/ping @svi3c

DorianGrey commented 7 years ago

I've fixed the mentioned issues, and extracted the shared module declaration and handling to a different PR - https://github.com/flaviait/ng2-jspm-template/pull/41.

The problem: Since we annot roll-up our app to global, we have an increased bundle size of ~400K (from 892K to 1284K).

I'll see if there is a solution to this - although it seems to be a more general problem: Different from e.g. webpack, the resulting bundles are not really linked to each other, thus, completely bundling them might not work in terms of rolling up (that's why I'd moved the code to use bundle so that System.registerDynamic takes care of this). However, the SystemJS runtime would be required anyway - it's used by Angular to load the target module.

svi3c commented 7 years ago

Right. I think a different npm script for the alternative module bundling would be great, so we can merge this to the master branch. There is quite a bunch of npm scripts by now, but I'm reducing them step by step issue within #39. Maybe we can even handle this by a simple flag in the config file I'm introducing.

DorianGrey commented 7 years ago

I'm afraid this won't be an easy task, since the parts of the bundling process are rather tightly connected to each other, like here: https://github.com/flaviait/ng2-jspm-template/pull/38/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R212

The only valuable thing I can think would be:

The only alternative would be to implement something like the tools in angular-cli already provide: Parsing the source and checking for use of lazy routes. Suppose this would be even more complicated - might be useful with a particular plugin, but these cannot be chained (atm.?) and thus would conflict with plugin-typescript. Kinda... problematic.

Thoughts?

svi3c commented 7 years ago

Yes, I'm currently implementing the usage of the JSPM API. Afterwards we may think of a well-suited solution.