static-html-bundler

raw JSON →
1.0.9 verified Sat Apr 25 auth: no javascript

A Node.js module that bundles and minifies CSS and JS assets referenced in HTML comment-bounded sections into single files. It reads an HTML entry point, replaces stylesheet link and script tags between user-defined start/end comment markers with a single combined and minified file per section. Version 1.0.9. No recent updates; relies on uglify-js and clean-css internally. Simpler than Webpack/Parcel but limited to comment-based bundling.

error Cannot find module './static-html-bundler/bundler'
cause Relative path incorrect or package not installed locally.
fix
Install via npm install static-html-bundler and require with correct path: require('./node_modules/static-html-bundler/bundler') or require('static-html-bundler') is not supported; use full relative path.
error TypeError: staticHtmlBundler.bundle is not a function
cause Importing with ESM syntax (import) instead of CommonJS require.
fix
Use const staticHtmlBundler = require('static-html-bundler/bundler'); (note: bare specifier may not work; use relative path).
error ENOENT: no such file or directory, open '...'
cause Source folder or input HTML path does not exist.
fix
Verify sourceFolder and inputHtml options point to existing files relative to the working directory.
gotcha Package only works with CommonJS require; no ESM or TypeScript support.
fix Use require() style and ensure Node.js version supports CommonJS.
breaking Requires exact comment markers in HTML; any mismatch (whitespace, typo) silently fails to bundle.
fix Verify start and end comment strings match exactly including HTML comment syntax.
gotcha Dist JS/CSS folder paths are concatenated directly; missing trailing slashes may produce incorrect output paths.
fix Ensure distJsFolder and distCssFolder have trailing slash (e.g., 'js/' rather than 'js').
deprecated No updates since 2017; relies on outdated uglify-js and clean-css versions which may have known issues.
fix Consider using modern alternatives like Webpack, Parcel, or Vite for active maintenance.
npm install static-html-bundler
yarn add static-html-bundler
pnpm add static-html-bundler

Demonstrates running static-html-bundler with common options for CSS and JS bundling via comment markers.

const staticHtmlBundler = require('./node_modules/static-html-bundler/bundler');
const options = {
  sourceFolder: './src/',
  distFolder: './dist/',
  distJsFolder: 'js/',
  distCssFolder: 'css/',
  inputHtml: './src/index.html',
  outputHtml: './dist/index.html',
  tags: [
    { start: '<!-- css bundle start -->', end: '<!-- css bundle end -->', type: 'css', name: 'styles' },
    { start: '<!-- js bundle start -->', end: '<!-- js bundle end -->', type: 'js', name: 'scripts' }
  ]
};
staticHtmlBundler.bundle(options);