diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-02-07 19:27:10 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-02-07 19:27:10 +0000 |
| commit | aecb9ed67bd2f73275442493b69e88e648273e56 (patch) | |
| tree | 695de8c683b8e08667438c9244d509d1374ee18b /README.md | |
| parent | bffdcda7eb215a636cfa9a17cc1af57620bd6822 (diff) | |
Clarify docs on use in the browser
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -125,12 +125,25 @@ In node.js, mammoth can be required in the usual way: var mammoth = require("mammoth"); ``` -To generate a standalone JavaScript file for the browser, -use `mammoth.browser.js` (generate using `make setup` if it is not already present). +This also works in the browser if node.js core modules +such as `Buffer` and `Stream`, are polyfilled. +Some bundlers, such as Webpack before version 5, will automatically polyfill these modules, +while others, such as Webpack from version 5, require the polyfills to be explicitly configured. + +Alternatively, you may use the standalone JavaScript file `mammoth.browser.js`, +which includes both mammoth and its dependencies. This uses any loaded module system. +For instance, when using CommonJS: + +```javascript +var mammoth = require("mammoth/mammoth.browser"); +``` + If no module system is found, `mammoth` is set as a window global. +The file can be generated using `make setup` during development. + #### Basic conversion To convert an existing .docx file to HTML, use `mammoth.convertToHtml`: |
