-
Notifications
You must be signed in to change notification settings - Fork 877
docs(cb-third-party-lib) create a third party lib #2758
Conversation
ee2bc6a
to
ecde57b
Compare
s s s s s c s c s s s s s s s s s s s s s s s s s s s s s s s s s
ecde57b
to
ab8e8ed
Compare
Ready for review: Here is my Third-Party-Library cookbook. The library is published with support for AoT and JiT builds. AoT files:: JS with esm modules, .d.ts and metadata.json, html, and css files JiT: files: umd bundle with inlined templates and css. The html/css inlining approach is currently using a script borrowed from material 2. The sample library is published to node_modules via a custom script triggered from add-example-boilerplate |
|
||
:marked | ||
Traditionally, third party JavaScript libraries have been published in the form of a single minified JavaScript file. | ||
Consumers of the library have then included the minified JavaScript file, "as is", somewhere on the page using a `script` tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally drop the "minified" mentions you have in here. It is more common to see unminified source now than minified. Your tool will always minify third party libraries. And even when you have both options, it is better to not add the minified versions. Angular for example strips all error messages from minified versions.
|
||
Modern web development has changed this process. Instead of publishing a "one size fits all" bundle, developers want to only include the parts of the library they actually need. | ||
|
||
This cookbook will show how to publish a third party library in a way that makes it possible to take advantage of techniques like Ahead of Time Compilation (AoT) and Tree shaking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid the word will
.
|
||
In addition to supporting AoT, the library code should also be "Tree Shakable". | ||
|
||
Thee Shakers work best with `ES2015` JavaScript. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tree
|
||
AoT compiled code is the prefered format for production builds, but due to the long compilation time, it may not be practical to use AoT during development. | ||
|
||
To create a more flexible developer experience, a JiT compatible build of the library should be published as well. The format of the JiT bundle is `umd`, which stands for Universal Module Definition. Shipping the bundle as `umd` ensures compatability with most common module loading formats. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compatibility
## Publish | ||
|
||
:marked | ||
`Rollup` wil create the `umd` bundle, but but prior to bundling, all external templates or css files must be inlined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No will (or wil :P)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double but.
I am more worried in teaching Webpack as well. There are a lot of libraries being published with a Webpack tooling and the would need guidance as well. |
@Foxandxss Thanks for the review. I have made tweaks based on your feedback. I am unsure about the Webpack part though. My thinking is that the most important take-away from this is learning what is required to be AoT compatible. Specifically, which files to include. I do agree that webpack seems to be very popular these days though. I have also seen feedback that people would like to see more webpack stuff in our AoT docs. What I find appealing about Rollup is that the configuration is simpler and requires less intensive tech stack explanations. However, I want to try to offer the most useful content to the users... @wardbell @robwormald Any feedback on whether it makes sense to include webpack here vs updating our existing webpack guide? |
Leave the webpack aside I guess. I would like to think about some ideas but I need to run all of them through Ward first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chapter looks good @thelgevold! It clarified a bunch of stuff for me, and I especially like how succinct it is.
I think we need to generalize and publish an angular/quickstart-lib
for people to use as well, but that can be done later.
I have a few change requests though, nothing major.
|
||
`tsconfig.json` for JiT compilation and `tsconfig-aot.json` for AoT compilation. | ||
|
||
+makeTabs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.ts
is mentioned elsewhere in the prose but not shown here.
|
||
+makeTabs( | ||
`cb-third-party-lib/hero-profile/hero-profile.module.ts, | ||
cb-third-party-lib/hero-profile/tsconfig-aot.json, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to actually only use one tsconfig.json
, but invoke it with overrides for the changed props?
For instance ngc --module=es2015
.
moduleId: module.id, | ||
selector: 'hero-profile', | ||
templateUrl: 'hero-profile.component.html', | ||
styleUrls: ['hero-profile.component.css'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3071 changed all paths to be relative, these should be as well.
+makeTabs( | ||
`cb-third-party-lib/hero-profile/hero-profile.module.ts, | ||
cb-third-party-lib/hero-profile/tsconfig-aot.json, | ||
cb-third-party-lib/ts/tsconfig.json, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make tsconfig.1.json
for this chapter with the config you want to show and use it here?
Our internal tsconfigs have some properties that shouldn't be shown to users:
"typeRoots": [
"../../node_modules/@types/"
]
"exclude": [
"node_modules/*",
"**/*-aot.ts",
"app-aot"
]
|
||
// AoT compile | ||
var spawnNgc = require( 'child_process' ).spawnSync; | ||
var ngc = spawnNgc('./public/docs/_examples/node_modules/.bin/ngc', ['-p', './public/docs/_examples/cb-third-party-lib/hero-profile/tsconfig-aot.json']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is the correct path for our tooling, it shouldn't be the path shown to users.
var fs = require('fs'); | ||
var del = require('del'); | ||
|
||
var node_modules_root = './public/docs/_examples/node_modules/hero-profile/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
var node_modules_root = './public/docs/_examples/node_modules/hero-profile/'; | ||
|
||
del.sync(node_modules_root, {force:true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this step for? It's not explained in the prose.
:marked | ||
## Final Application | ||
|
||
If you have cloned the `Angular.io` repo, all the steps described in this cookbook can be executed by running the following command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to give people instructions on how to build a sample lib outside of angular.io. Something like a angular/quickstart-lib
, side by side with angular/quickstart
.
This is something I can do later and should not block the release of this chapter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense. Some of the complexity comes from having to simulate an npm dependency, and at the same time, make it work with the angular.io workflow.
I think most of the value is in teaching what types of files are necessary to make the library AoT compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's also useful to describe the umd part of the library and its use.
Superseded by #3411 |
WIP. Do not merge