Skip to content

Commit

Permalink
Transpile UMD dist to ES5
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Jul 8, 2018
1 parent 3b28f6e commit 6ebda8b
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 350 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,39 @@ export function encode(samples) {}
export function decode(samples) {}
```

## Distribution
This library is a ES module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with ```npm install alawmulaw```. It includes a TypeScript definition file.

If you use the [Closure Compiler](https://github.com/google/closure-compiler), this package includes a externs file: **./externs.js**.

### If you are using this lib in a browser:

You may load both **./dist/alawmulaw.umd.js** and **./dist/alawmulaw.min.js** in the browser with ```<script>``` tags. Ideally you should use **alawmulaw.min.js**. You can load it via the https://unpkg.com and https://www.jsdelivr.com/ CDNs:

[unpkg](https://unpkg.com/alawmulaw):
```html
<script src="https://unpkg.com/alawmulaw"></script>
```

[jsDelivr](https://cdn.jsdelivr.net/npm/alawmulaw):
```html
<script src="https://cdn.jsdelivr.net/npm/alawmulaw"></script>
```

### If you are using this lib as a dependency:

- The **CommonJS** dist is **./dist/alawmulaw.cjs.js**. It is the dist file used by Node. It is served in the "main" field of package.json and is the source you are running when you **npm install alawmulaw**. It is not compiled or minified.

- The **UMD** module is **./dist/alawmulaw.umd.js**. It is transpiled to ES5 and compatible with Node, AMD and browsers. It is served in the "browser" field of package.json.

- The **browser-only** dist is **./dist/alawmulaw.min.js**. It is transpiled to ES5 and compiled. It is used in the "unpkg" and "jsdelivr" fields of package.json.

- The **ES6 dist** is **./dist/alawmulaw.js**, served as "es2015" in package.json. It is not compiled/minified.

- **./main.js** is served as "module" in package.json. This should be the entry point for bundlers.

If your module bundler is using "browser" as the entry point **your dist should work the same** but will be a larger file.

## References
https://github.com/torvalds/linux/blob/master/sound/core/oss/mulaw.c
https://github.com/deftio/companders
Expand Down
20 changes: 11 additions & 9 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# Distribution
This library is a ES6 module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with ```npm install alawmulaw```.
This library is a ES module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with ```npm install alawmulaw```. It includes a TypeScript definition file.

If you use the [Closure Compiler](https://github.com/google/closure-compiler), this package includes a externs file: **./externs.js**.

## If you are using this lib in a browser:

You may load both **alawmulaw.umd.js** and **alawmulaw.min.js** in the browser with ```<script>``` tags. Ideally you should use **alawmulaw.min.js**. You can load it via the https://unpkg.com and https://www.jsdelivr.com/ CDNs:
You may load both **./dist/alawmulaw.umd.js** and **./dist/alawmulaw.min.js** in the browser with ```<script>``` tags. Ideally you should use **alawmulaw.min.js**. You can load it via the https://unpkg.com and https://www.jsdelivr.com/ CDNs:

[unpkg](https://www.unpkg.com):
[unpkg](https://unpkg.com/alawmulaw):
```html
<script src="https://unpkg.com/alawmulaw"></script>
```

[jsDelivr](https://www.jsdelivr.com):
[jsDelivr](https://cdn.jsdelivr.net/npm/alawmulaw):
```html
<script src="https://cdn.jsdelivr.net/npm/alawmulaw"></script>
```

## If you are using this lib as a dependency:

- The **CommonJS** is the dist file used by Node. It is served in the "main" field of package.json. It includes all the sources but no dependencies. Dependencies will be imported from the **node_modules** folder. This is the source you are running when you **npm install alawmulaw**.
- The **CommonJS** dist is **./dist/alawmulaw.cjs.js**. It is the dist file used by Node. It is served in the "main" field of package.json and is the source you are running when you **npm install alawmulaw**. It is not compiled or minified.

- The **UMD** module is compatible with Node, AMD and browsers. It is served in the "browser" field of package.json. It includes all dependencies. This file is not compiled/minified as it may be used by module bundlers. Compilation/minification should be up to the bundler consuming this file.
- The **UMD** module is **./dist/alawmulaw.umd.js**. It is transpiled to ES5 and compatible with Node, AMD and browsers. It is served in the "browser" field of package.json.

- The **compiled dist** is browser-only and should be the one served by CDNs. It includes all the dependencies. It is used in the "unpkg" and "jsdelivr" fields of package.json.
- The **browser-only** dist is **./dist/alawmulaw.min.js**. It is transpiled to ES5 and compiled. It is used in the "unpkg" and "jsdelivr" fields of package.json.

- The **ES6 dist** is **alawmulaw.js**, served as "es2015" in package.json. It includes all the dependencies. It is not compiled/minified.
- The **ES6 dist** is **./dist/alawmulaw.js**, served as "es2015" in package.json. It is not compiled/minified.

- **./index.js** is served as "module" in package.json. It should be used by systems that support ES modules and are aware of Node's module path resolution (a module bundler, for instance). This should be the entry point for bundlers in most cases - this will avoid code duplication in the case of shared dependencies (as opposed to using "browser" as the entry point).
- **./main.js** is served as "module" in package.json. This should be the entry point for bundlers.

If your module bundler is using "browser" as the entry point **your dist should work the same** but will be a larger file.

Expand Down
Loading

0 comments on commit 6ebda8b

Please sign in to comment.