Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 43bf280

Browse files
committed
add entry points and build step
1 parent 97434e4 commit 43bf280

File tree

1 file changed

+73
-8
lines changed

1 file changed

+73
-8
lines changed

public/docs/ts/latest/cookbook/third-party-lib.jade

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ a#seed
149149

150150
Libraries do not run by themselves, so it's very useful to have this "demo" app while developing
151151
to see how your library would look like to consumers.
152+
153+
When you run `npm start`, the demo application is served.
152154

153155
The following are all in `src/`
154156

@@ -173,7 +175,7 @@ table(width="100%")
173175
td <ngio-ex>lib/component/app.component.ts</ngio-ex>
174176
td
175177
:marked
176-
A sample library component that renders an `h2` tag.
178+
A sample library component that renders an `<h2>` tag.
177179
tr
178180
td <code>lib/service/lib.service.ts</code>
179181
td
@@ -191,31 +193,94 @@ table(width="100%")
191193
The library's main `NgModule`, `LibModule`.
192194

193195

196+
.l-main-section
197+
:marked
198+
## Entry points
199+
200+
In order to understand how to build and publish a library, you have to consider _how_ the library is going to be consumed.
201+
202+
Some users need to add it as a `<script>` tag.
203+
Others might be using SystemJS instead.
204+
Bundlers, like Webpack, are very popular as well.
205+
Typescript users need type definitions.
206+
Rollup users make use of ECMAScript modules for tree-shaking.
207+
AOT applications need library metadata to compile.
208+
209+
It's daunting to think of all the ways your library might be used and how to accomodate it,
210+
but you don't need to have a "one-size-fits-all" library.
211+
212+
You can configure `package.json` with more entry points besides [main](https://docs.npmjs.com/files/package.json#main).
213+
214+
The **Quickstart Library** seed uses a similar set of entry points as Angular itself,
215+
aimed at maximizing compatibility:
216+
217+
- `main` (default): an ES5 [UMD](https://github.com/umdjs/umd) bundle that can be consumed anywhere.
218+
- `module`: a flat ECMAScript module (FESM) bundle containing ES5 code.
219+
- `es2015`: a FESM containing ES2015 bundle.
220+
- `typings`: TypeScript and the AOT compiler will look at this entry for metadata.
221+
222+
code-example(language="json").
223+
"main": "./dist/angular-quickstart-lib.umd.js",
224+
"module": "./dist/angular-quickstart-lib.es5.js",
225+
"es2015": "./dist/angular-quickstart-lib.js",
226+
"typings": "./dist/angular-quickstart-lib.d.ts",
227+
228+
:marked
229+
There is also a minified UMD bundle (`angular-quickstart-lib.umd.min.js`) for smaller payloads
230+
in Plunkers and script tags.
231+
232+
.l-sub-section
233+
:marked
234+
A flat ECMAScript module (FESM) is a bundled ECMAScript module where all imports were followed
235+
copied onto the same file file.
236+
It always contains ES module import/export statements but can have different levels of ES code
237+
inside.
238+
239+
.l-main-section
240+
:marked
241+
## The build step
242+
243+
You can build the library by running `npm run build`.
244+
This will generate a `dist/` directory with all the entry points described above.
245+
246+
All the logic for creating the build can be found in `./build.js`. It consists of roughly 4 steps:
247+
248+
- Compile with `ngc` for ES5 and ES2015.
249+
- Inline html and css inside the generated JavaScript files.
250+
- Copy typings, metatada, html and css.
251+
- Create each bundle using rollup.
252+
253+
.l-main-section
254+
:marked
255+
## Testing
256+
257+
content
194258

195259
.l-main-section
196260
:marked
197-
## Rename your library
261+
## Publishing your library
198262

199263
Every package on NPM has a unique name, and so should yours.
200264

201265
-- rename lib
202266

203-
.l-sub-section
204-
:marked
205-
### Next Step
267+
.l-main-section
268+
:marked
269+
## title
206270

207-
If you're new to Angular, we recommend staying on the [learning path](learning-angular.html "Angular learning path").
271+
content
208272

209273

210274
.l-main-section
211275
:marked
212-
## Appendix: library-setup-anatomy
276+
## title
213277

214278
content
215279

280+
216281
.l-main-section
217282
:marked
218-
## Appendix: testing libraries
283+
## Appendix: Library Setup Anatomy
219284

220285
content
221286

0 commit comments

Comments
 (0)