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

docs(cb-third-party-lib) create a third party lib #2758

Closed
wants to merge 2 commits into from

Conversation

thelgevold
Copy link
Contributor

WIP. Do not merge

@thelgevold thelgevold force-pushed the cb-third-party-lib branch 4 times, most recently from ee2bc6a to ecde57b Compare November 5, 2016 21:45
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
@thelgevold thelgevold changed the title WIP: docs(cb-third-party-lib) create a third party lib docs(cb-third-party-lib) create a third party lib Nov 5, 2016
@thelgevold
Copy link
Contributor Author

thelgevold commented Nov 5, 2016

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

@wardbell @robwormald @filipesilva @Foxandxss


: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.
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double but.

@Foxandxss
Copy link
Member

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.

@thelgevold
Copy link
Contributor Author

thelgevold commented Nov 7, 2016

@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?

@Foxandxss
Copy link
Member

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.

Copy link
Contributor

@filipesilva filipesilva left a 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(
Copy link
Contributor

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,
Copy link
Contributor

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']
Copy link
Contributor

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,
Copy link
Contributor

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']);
Copy link
Contributor

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/';
Copy link
Contributor

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});
Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@filipesilva
Copy link
Contributor

Superseded by #3411

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants