@@ -149,6 +149,8 @@ a#seed
149
149
150
150
Libraries do not run by themselves, so it's very useful to have this "demo" app while developing
151
151
to see how your library would look like to consumers.
152
+
153
+ When you run `npm start`, the demo application is served.
152
154
153
155
The following are all in `src/`
154
156
@@ -173,7 +175,7 @@ table(width="100%")
173
175
td <ngio-ex >lib/component/app.component.ts</ngio-ex >
174
176
td
175
177
:marked
176
- A sample library component that renders an `h2 ` tag.
178
+ A sample library component that renders an `<h2> ` tag.
177
179
tr
178
180
td <code >lib/service/lib.service.ts</code >
179
181
td
@@ -191,31 +193,94 @@ table(width="100%")
191
193
The library's main `NgModule`, `LibModule`.
192
194
193
195
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
194
258
195
259
.l-main-section
196
260
:marked
197
- ## Rename your library
261
+ ## Publishing your library
198
262
199
263
Every package on NPM has a unique name, and so should yours.
200
264
201
265
-- rename lib
202
266
203
- .l-sub -section
204
- :marked
205
- ### Next Step
267
+ .l-main -section
268
+ :marked
269
+ ## title
206
270
207
- If you're new to Angular, we recommend staying on the [learning path](learning-angular.html "Angular learning path").
271
+ content
208
272
209
273
210
274
.l-main-section
211
275
:marked
212
- ## Appendix: library-setup-anatomy
276
+ ## title
213
277
214
278
content
215
279
280
+
216
281
.l-main-section
217
282
:marked
218
- ## Appendix: testing libraries
283
+ ## Appendix: Library Setup Anatomy
219
284
220
285
content
221
286
0 commit comments