0
votes

How should one package angular2 components in a mpm module so it can be imported and used in an application compiled with angular-cli@webpack.

What should be published in the npm package ? The source (*.ts, *.css, *.html) or the webpack compiled version ?

see my related question : angular-cli@webpack : Components imported in npm dependencies don't work

1

1 Answers

0
votes

First, install Yeoman and generator-angular2-library using npm (assuming you already have node.js pre-installed).

$ npm install -g yo
$ npm install -g generator-angular2-library

make a new directory and cd into it:

$ mkdir angular2-library-name
$ cd angular2-library-name

and generate your new library:

$ yo angular2-library

and create the following files for you:

.
├── README.MD
├── index.ts
├── package.json
├── src
│   ├── sample.component.ts
│   ├── sample.directive.ts
│   ├── sample.pipe.ts
│   └── sample.service.ts
├── tsconfig.json
├── tslint.json
└── typings.json

You can then add or edit *.ts files in the src/ directory and run:

$ npm run tsc
$ npm run lint

Once you have published your library to the NPM registry, you can import it in any Angular application by first installing it using NPM:

$ npm install sample-library # use the name you used to publish to npm

Detailed description available here.