Skip to content

Conversation

@29217321
Copy link

@29217321 29217321 commented Jan 21, 2026

This PR introduces a standalone browser build that bundles all dependencies into a single file, enabling direct usage of html-to-docx in browser environments without any build tools or module bundlers.

Usage Example:

<script src="path/to/html-to-docx.browser.js"></script>
<script>
  const result = await HTMLToDOCX('<h1>Hello World</h1>');
  // Download as DOCX file...
</script>

Testing
Run> npm run build
Run> npm run test:browser
Open [http://localhost:8080/tests/test_browser.html]

@nicolasiscoding
Copy link
Member

Love this!!

@K-Kumar-01 K-Kumar-01 changed the base branch from develop to ft/browser_build January 22, 2026 16:08
Copy link
Collaborator

@K-Kumar-01 K-Kumar-01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @29217321 🚀

I am approving the PR. Just added few comments. Can you please clarify them?

@29217321 29217321 force-pushed the develop branch 2 times, most recently from f9949d0 to 5067192 Compare January 23, 2026 08:02
@nicolasiscoding
Copy link
Member

Code review

Found 4 issues:

1. Buffer polyfill missing from README documentation

The README's browser usage example (lines 213-216) shows polyfills for global and process, but is missing the critical Buffer polyfill that's included in the working test file.

Issue: Users following the README will encounter runtime errors like Buffer is not defined when generating documents with images or SVG content, because the library uses Buffer.from() extensively throughout the codebase for base64 image processing.

Evidence:

  • README polyfills: only global and process shown
  • test_browser.html (lines 162-167): includes complete Buffer polyfill
  • Library code uses Buffer in 9+ locations for image/SVG processing

html-to-docx/README.md

Lines 213 to 216 in 090b23b

<script>
if (typeof global === 'undefined') window.global = window;
if (typeof process === 'undefined') window.process = { env: {} };
</script>

Fix: Add the Buffer polyfill to the README example:

if (typeof Buffer === 'undefined') {
  window.Buffer = {
    from: function(arr) { return new Uint8Array(arr); },
    isBuffer: function() { return false; }
  };
}

2. Outdated documentation contradicts new browser support implementation

The README contains a note stating "Browser support is planned for future releases" but this PR implements browser support with comprehensive documentation (lines 174-291).

Issue: This creates confusion for users who read extensive browser build documentation earlier in the README, then see a note saying it's not yet available. The note should be removed or updated to reflect that browser support is now implemented.

**Note:** Currently optimized for Node.js environments. Browser support is planned for future releases.


3. Missing cleaner plugin in browserConfig

The browserConfig doesn't include the cleaner plugin that's present in libraryConfig (lines 28-30), which will cause stale build artifacts when using BUILD_TARGET=browser.

Issue: When building browser-only (npm run build:browser or npm run build:browser:prod), the rollup config exports only [browserConfig] (line 86), which means the cleaner plugin never runs and old files won't be removed from dist/.

const browserConfig = {
input: 'index.js',
// Only exclude sharp (Node.js native module, not supported in browser)
external: ['sharp'],
plugins: [
resolve({
browser: true,
preferBuiltins: false,
}),
json(),
commonjs(),
nodePolyfills(),
terser({
mangle: isProduction,
compress: isProduction,
}),
],
output: {
file: 'dist/html-to-docx.browser.js',
format: 'iife',
name: 'HTMLToDOCX',
sourcemap: !isProduction,
banner,
// Provide empty implementation for sharp in browser environment
globals: {
sharp: '(() => null)',
},
},
};

Fix: Add the cleaner plugin to browserConfig:

cleaner({
  targets: ['./dist/']
}),

4. Manual polyfills still required despite rollup-plugin-polyfill-node

The PR adds rollup-plugin-polyfill-node to bundle polyfills automatically, but users still need to manually add global, process, and Buffer polyfills. This suggests the bundled polyfills aren't sufficient.

Context: Issues #97 and #137 indicate the project goal is to remove polyfill requirements for browser usage, but this implementation still requires manual polyfills.

Recommendation: Either:

  • Document why manual polyfills are still needed despite the rollup plugin
  • Or investigate why the bundled polyfills aren't eliminating the need for manual ones

html-to-docx/README.md

Lines 212 to 216 in 090b23b

<!-- Polyfills for Node.js globals (required) -->
<script>
if (typeof global === 'undefined') window.global = window;
if (typeof process === 'undefined') window.process = { env: {} };
</script>


🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@nicolasiscoding
Copy link
Member

@29217321 we appreciate your patience, our apologies that the claude code review comments were not posted. Can you address the above, and for each of these add a comment with the commit hash or explain why you think the comment should not be addressed? I want to get this out ASAP and have someone/claude work on updating the React example. cc @K-Kumar-01

@nicolasiscoding nicolasiscoding self-requested a review January 25, 2026 18:00
Copy link
Member

@nicolasiscoding nicolasiscoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address claude code comments and add commit hashes for each item fixed, or an explanation why it may not be needed

@29217321
Copy link
Author

@nicolasiscoding Thanks for the comments, fixed 1-3 and added a comments to explain why is polyfills still required now, please check out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants