Creation d’une lib javascript

Ref : https://shellmonger.com/2016/03/11/creating-javascript-libraries-with-typescript-and-webpack/

Utilisation

Import

1
<script src="http://localhost:8082/MyLib.min.js"></script>

Definition dans le composant

1
2
3
4
5
6
7
8
9
10
declare var MyLib: any;

@Component({
selector: 'preview',
templateUrl: 'preview.template.html'
})
export class PreviewComponent {

constructor(private configService: ConfigService, private previewQuestionnaireService: PreviewQuestionnaireService) {
new MyLib.TestClass('foo');

Creation d’une lib Angular2

Yeoman generator to create a standalone Angular 2 library

Ref : https://github.com/jvandemo/generator-angular2-library

Utilisation

1
npm install ng2-book-lib (ou npm link/npm install)

Dans vendor.ts, declarer la lib

1
import 'ng2-book-lib';

Import dans le module principal

1
2
3
4
5
6
7
8
9
10
import { SampleModule } from 'ng2-book-lib';
....
@NgModule({
imports: [
BrowserModule,
HttpModule,
...

SampleModule.forRoot(),
....

Ensuite, les composants, services de la lib sont disponibles dans l’application principale

Angular2 Seed avec SystemJS
https://github.com/mgechev/angular-seed
http://stackoverflow.com/questions/36091219/how-to-load-angular2-using-cdn
http://lishman.io/angular-2-configuration

Angular Library
https://www.hellohq.io/how-to-set-up-an-angular-2-component-library/
http://blog.angular-university.io/how-to-create-an-angular-2-library-and-how-to-consume-it-jspm-vs-webpack/
https://github.com/lucasbauche/MyAngularLibrary
https://github.com/jhades/angular2-library-example
https://dzone.com/articles/create-an-angular-2-component-library-and-consume
https://www.thepolyglotdeveloper.com/2016/01/include-external-javascript-libraries-in-an-angular-2-typescript-project/

Voir pangiate et translate
https://github.com/ocombe/ng2-translate
https://unpkg.com/ng2-translate@5.0.0