Bundle browser script, add package exports, add sourcemaps

This commit is contained in:
Tomás Fox
2022-03-15 15:27:19 -03:00
parent ab5cfd8582
commit e447a242c7
13 changed files with 1028 additions and 80 deletions

View File

@@ -1,5 +1,4 @@
ffprobe-wasm
==========
# ffprobe-wasm
Gather information from multimedia streams. Works on the browser and Node.js.
@@ -18,25 +17,30 @@ npm install ffprobe-wasm
Node.js
```ts
import { FFprobeWorker } from 'ffprobe-wasm/node.mjs';
import { FFprobeWorker } from "ffprobe-wasm";
const worker = new FFprobeWorker();
const fileInfo = await worker.getFileInfo('file.mp4');
const fileInfo = await worker.getFileInfo("file.mp4");
console.log(fileInfo);
```
Browser
```ts
import { FFprobeWorker } from 'ffprobe-wasm/browser.mjs';
import { FFprobeWorker } from "ffprobe-wasm";
const worker = new FFprobeWorker();
// input is the reference to a <input type="file" /> element
input.addEventListener('change', (event) => {
const file = event.target.files[0]
// input is the reference to an <input type="file" /> element
input.addEventListener("change", (event) => {
const file = event.target.files[0];
const fileInfo = await worker.getFileInfo(file);
console.log(fileInfo);
});
```
## Notes
- In browser, `SharedArrayBuffer` is being used. To enable this in your server, read [Security requirements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements).
- In browser, everything is bundled in the `browser.mjs` script. When gzipped, this file is bigger than 1 MiB, so it's recommended to use `import()` to lazy load the asset. The good side of this is that you don't have to configure your bundler to include the worker or wasm files and you won't face [same-origin](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) issues with the worker.