最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between SystemJS and CommonJS - Stack Overflow

programmeradmin9浏览0评论

I see there are article explaining difference between commonJs and AMD but I am unable to relate between commonJS and SystemJS. Both of these are used in AngularJS 2 development. As both of these are module loader then why do we require both?

I see there are article explaining difference between commonJs and AMD but I am unable to relate between commonJS and SystemJS. Both of these are used in AngularJS 2 development. As both of these are module loader then why do we require both?

Share Improve this question edited Oct 25, 2016 at 11:03 Nishant asked Oct 25, 2016 at 10:55 NishantNishant 1,0441 gold badge9 silver badges19 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 8

CommonJS is a specification while SystemJS is opensource Javascript a loader which follows specifications like CommonJS. CommonJS specification defines how modules in JavaScript work , how they can be exposed and how they can be called. SystemJS is a loader which follows CommonJS specs and other specs.

Below is a simple 20 minutes youtube video tutorial which explains how CommonJS module specs look like and how SystemJS respects that spec.

https://www.youtube.com/watch?v=jN4IM5tp1SE

CommonJS is used in NodeJS to require modules at build time. E.g. the modules are compiled and are then delivered to the browser with all code loaded up front.

SystemJS however replaces requireJS. SystemJS loads modules dynamically at run time. In Angular2 if you watch your browser's NET tab you will see SystemJS loading files as you explore more parts of you app.

You could require a module inside a click event handler or something too.

发布评论

评论列表(0)

  1. 暂无评论