1 | 
|
2 | [](https://opensource.org/licenses/MIT)
|
3 | [](https://www.npmjs.com/package/@platform/ts)
|
4 |
|
5 | # ts
|
6 |
|
7 | [TypesScript](https://www.typescriptlang.org) build, prepare and publish toolchain.
|
8 |
|
9 | Provides:
|
10 |
|
11 | - Command line for building, linting, preparing for publish and ultimately publishing.
|
12 | - Produces CommonJS and modern ESM transpiled builds.
|
13 | - Publishes to NPM from the distribution older, removing unnecesary pathing into the module from consumers (eg. '@my-modules/lib/...` is avoided).
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | ## Commands
|
19 | Adds the `ts` command to your module's `bin`. You can optionally use the following scripts in you `package.json`:
|
20 |
|
21 | ```json
|
22 | {
|
23 | "scripts: {
|
24 | "test": "ts test",
|
25 | "tdd": "ts test --watch",
|
26 | "lint": "ts lint",
|
27 | "build": "ts build",
|
28 | "prepare": "ts prepare",
|
29 | }
|
30 | }
|
31 | ```
|
32 |
|
33 | To build without ESM module compilation:
|
34 |
|
35 | ```json
|
36 | {
|
37 | "scripts: {
|
38 | "build": "ts build --no-esm",
|
39 | }
|
40 | }
|
41 | ```
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | ## ESModules
|
47 | When setting the `main` of package.json make sure to not include the `.js` file extensions allowing environments that as using [ESModule's](https://developers.google.com/web/fundamentals/primers/modules) to infer the `.msj` version.
|
48 |
|
49 | ```json
|
50 | {
|
51 | "name": "my-module",
|
52 | "main": "index",
|
53 | "types": "index.d.ts"
|
54 | }
|
55 | ```
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | ## References:
|
61 |
|
62 | - **ECMAScript Modules** (ESM)
|
63 | - [Using JavaScript modules on the web](https://developers.google.com/web/fundamentals/primers/modules) - Google/Primer
|
64 | - [ECMAScript modules in Node.js: the new plan](http://2ality.com/2018/12/nodejs-esm-phases.html) - December 2018
|
65 | - [ES6 Modules Today With TypeScript](https://www.ceriously.com/blog/post.php?id=2017-10-16-es6-modules-today-with-typescript.md) - recipe used.
|
66 |
|