diff --git a/README.md b/README.md index ce9ef23..ace0db1 100755 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ You can find an example implementation of `saveDataToFile()` [in the Webpack exa Check out the examples [using Webpack](https://github.com/guigrpa/docx-templates/tree/master/examples/example-webpack) and [using Browserify](https://github.com/guigrpa/docx-templates/tree/master/examples/example-browserify) or you can use the browserified bundle directly as discussed below. ## Polyfilled browser-ready bundle -As this library depends on the internal NodeJS modules `vm`, `stream`, `util`, and `events`, your build tools have to polyfill these modules when using the library in the browser. We provide a browser build which includes the required polyfills. Its file size is about 300K uncompressed or 85K / 70K with gzip / brotli compression). +As this library depends on the internal NodeJS modules `vm`, `stream`, `util`, `events` and the `Buffer` global, your build tools have to polyfill these modules when using the library in the browser. We provide a browser build which includes the required polyfills. Its file size is about 300K uncompressed or 85K / 70K with gzip / brotli compression). You can import the library directly **as a module** using e.g. the unpkg.com CDN, like below, or you can host the `/lib/browser.js` bundle yourself. diff --git a/src/browser-polyfill.ts b/src/browser-polyfill.ts new file mode 100644 index 0000000..4286fa9 --- /dev/null +++ b/src/browser-polyfill.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { Buffer } from 'buffer/'; + +(globalThis).Buffer = Buffer; diff --git a/src/browser.ts b/src/browser.ts index ea465c2..e4cf58f 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1 +1,2 @@ +import './browser-polyfill'; export * from './index';