There are related instructions in Writing NPM modules in Typescript , however it's dated and there are now a lot of different answers which may or may not work for angular 4. There's also a very good presentation by Jason Aden on youtube on how to publish Angular Components, but in this case I'm only interested in publishing vanilla typescript classes.
We have two classes:
export class Student{...} // inside src/Person.ts
export class Teacher{...} // inside src/Teacher.ts
Lets call this module university
and assume that it can be installed by doing npm i --save university
.
Inside the Angular 4 project that has university
as a dependency we create a src/Schedule.ts
class. How should the university
module be configured WRT package.json, tsconfig.json, etc such that:
1) IDE (Visual Studio, Atom, etc.) get auto completion
2) The Student
class can be imported by specifying import {Student} from 'university`;
3) If only Student
is used, the rest of the university module is excluded by the Angular CLI production build (Tree shaking).
via Ole
No comments:
Post a Comment