2

There's something I'm not sure to understand with ES6 module import and Angular (although it's not restrcited to Angular)

When I'm importing a component like this :

import { Component } from '@angular/core';

Ok I'm importing the Component class from @angular/core package.

But if I go to node_modules : there's no Component class file at the root of @angular/core. I can see some bundle, esm5, esm2015 and src packages and also files like core.d.ts at the root. How the module loader manages to understand where this Component is located ?

Thanks

AntonBoarf
  • 1,239
  • 15
  • 31
  • 1
    If you don't specify a file name to import, `index.ts/js` will be used (@angular/core/index.ts). You can go from this file up the tree (there are many files that only export in between) – baao Jun 07 '18 at 16:51

1 Answers1

1

When you importing @angular/core module, it will look for package.json in the module root that is node_modules/@angular/core folder. And then look for main property which is the main entry point of the module. This is the file you want.

enter image description here

Will Huang
  • 2,955
  • 2
  • 37
  • 90
  • Ok than you. I can see that in package.json there's a main attribute (core.umd.js) and also a module attributre (core.js). Are they the same thing ? – AntonBoarf Jun 07 '18 at 18:31
  • @AntonBoarf There are different module coding pattern. So their source code are different in module system only. – Will Huang Jun 07 '18 at 18:53