PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

[Question] Why using SystemJS to load async feature areas ?

Open mildful opened this issue 10 years ago • 8 comments

  • I'm submitting a ... [ ] bug report [ ] feature request [x] question about the decisions made in the repository
  • Question:

Since the release of RC5 and NgModule, you are using System.import to load modules asynchronously. I was just wondering why. Since we are using webpack, is it redundant to have SystemJS ?

  • Please tell us about your environment:

Angular version: 2.0.0-rc.5

mildful avatar Sep 07 '16 09:09 mildful

I also would like to know this. We were using es6-promise-loader before right?

paralin avatar Sep 08 '16 04:09 paralin

Maybe because is the recommended way by the Angular 2 staff, however since this repo was already working with es6-promise-loader i do wonder why.

luchillo17 avatar Sep 08 '16 05:09 luchillo17

Do not confuse System.import with SystemJS. System.import is to have dynamic imports and SystemJS is the Polyfill to allow to do this today. System.import is using ES6 promises, so not much different then what es6-promise-loader does. See here

katallaxie avatar Sep 08 '16 16:09 katallaxie

That does make sense, instead of depending on that loader is best to rely on SystemJS to polyfill the System.import that JS is supposed to have in the future, basically getting ready for the future hoping some day we could drop the SystemJS library used to polyfill the import.

@katallaxie Is that right?

luchillo17 avatar Sep 08 '16 18:09 luchillo17

No, I think there are 2 things with the same name : SystemJS.

On one hand, there is the SystemJS that we all know - the module loader - and on the other hand there is the module loader API for ES6, the one we are using here.

I heard about it but I didn't know that they have the same name.

_ I'm not sure but that is what I understand._

mildful avatar Sep 08 '16 19:09 mildful

@mildful SystemJS wants to harvest the same mechanism as System.import will do. Dynamically load modules. They provide an API based on Promise, which is polyfilled, that emulates this of System.import. What SystemJS and Webpack do in addition, is to produce these modules. So, the goal of SystemJS is, to have System.import work today, in all browsers, and to have the modules produced.

katallaxie avatar Sep 08 '16 19:09 katallaxie

So it is in deed working as a polyfill in this context.

luchillo17 avatar Sep 09 '16 00:09 luchillo17

We are using the keywords System.import but it's not related to SystemJS since it's inlined as promises. Webpack 2 gives us this new promise base syntax which allows us to use that rather than our callback style syntax workaround wrapper (es6-promise-loader) require.ensure. Also, note that SystemJS uses the SystemJS global now to be backwards compatible with the future browser loader spec. See guybedford/systemjs-webpack-plugin that will allow SystemJS and Webpack to work together.

PatrickJS avatar Sep 09 '16 04:09 PatrickJS