Skip to content

Commit

Permalink
Restore Buffer polyfill to support e1032d9
Browse files Browse the repository at this point in the history
Revert "Issue #345: Remove unnecessary polyfill."

This reverts commit 99930b5.
  • Loading branch information
jjhbw committed Sep 25, 2024
1 parent d94eb73 commit 277cb58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions src/browser-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Buffer } from 'buffer/';

(<any>globalThis).Buffer = Buffer;
1 change: 1 addition & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './browser-polyfill';
export * from './index';

0 comments on commit 277cb58

Please sign in to comment.