Registry / devops / html2js-browserify

html2js-browserify

JSON →
library1.3.0jsnpmunverified

Browserify transform that converts HTML files into JavaScript modules by generating a JS string from the HTML content. Version 1.3.0 is the latest stable release. It integrates with Browserify's transform pipeline, allowing HTML files to be required as strings in Node.js/browser code. Supports optional minification via html-minifier. Differentiates from other HTML require transforms by its simple pass-through of options to html-minifier.

npm install html2js-browserify
INSTALL
IMPORT
SIG · HTML2JS-BROWSERIFY
H
html2js-browserify
devopsjavascriptv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

html2js-browserify (transform)
browserify -t html2js-browserify app.js
This is a Browserify transform, not a library import. Use via command line or package.json browserify.transform array.

Shows how to require an HTML file after applying the Browserify transform.

// index.js var html = require('./template.html'); console.log(html); document.body.innerHTML = html; // package.json { "browserify": { "transform": ["html2js-browserify"] } } // Run: browserify index.js > bundle.js
Debug
Known issues
gotchaTransform must be applied via browserify -t or package.json browserify.transform
fix
Ensure browserify runs with -t html2js-browserify or set in package.json
affects: >=1.0.0
deprecatedBrowserify transforms are less common now; consider using webpack or esbuild with raw-loader
fix
Use a modern bundler or switch to import HTML as a raw string
affects: >=1.0.0
gotchaMinification options must be passed after --minify, e.g. --collapseWhitespace
fix
Pass all html-minifier options after --minify
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module './some.html'
Browserify transform not applied
fix
Run browserify with -t html2js-browserify or set transform in package.json
TypeError: html is not a string
HTML file not transformed; returns an empty object
fix
Verify the transform is correctly registered and browserify is run with the transform flag
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
throughrequiredUsed to create the transform stream for Browserify
html-minifieroptionalOptional dependency for minification when --minify flag is set
Agent activity
4 hits · last 30 days
node
4
Resources
html2js-browserify — npm install html2js-browserify · libregistry