From aecb9ed67bd2f73275442493b69e88e648273e56 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 7 Feb 2023 19:27:10 +0000 Subject: Clarify docs on use in the browser --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c477dad..8512ffe 100644 --- a/README.md +++ b/README.md @@ -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`: -- cgit v1.2.3