Registry / devops / metalsmith-js-packer

metalsmith-js-packer

JSON →
library0.2.0jsnpmunverified

Metalsmith plugin that packs, minifies, and uglifies JavaScript files from HTML pages. Version 0.2.0 (last released in 2020, no recent updates). It scans generated HTML for script tags (external, inline, internal), bundles them into a single minified file, and writes the result to the filesystem. Supports excluding specific scripts via data-packer attribute, inline output mode, custom output path, and uglify options. Designed for Metalsmith static site generator workflows. Alternative to metalsmith-in-place or manual webpack/gulp integration for JS bundling.

npm install metalsmith-js-packer
INSTALL
IMPORT
SIG · METALSMITH-JS-PACK
M
metalsmith-js-packer
devopsjavascriptv0.2.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.

default
const jsPacker = require('metalsmith-js-packer');
import jsPacker from 'metalsmith-js-packer';
This package does not ship ESM; require() is the only supported import.
jsPacker
const jsPacker = require('metalsmith-js-packer'); metalsmith.use(jsPacker());
metalsmith.use(jsPacker);
jsPacker is a factory function, must be called with options (or empty).
options
const jsPacker = require('metalsmith-js-packer'); metalsmith.use(jsPacker({ inline: true, outputPath: 'js/' }));
metalsmith.use(jsPacker({ inline: true }, { outputPath: 'js/' }));
Options are passed as a single object to the factory function.

Basic Metalsmith build with js-packer plugin minifying JavaScript into a single file.

const metalsmith = require('metalsmith'); const jsPacker = require('metalsmith-js-packer'); metalsmith(__dirname) .source('./src') .destination('./build') .use(jsPacker({ inline: false, siteRootPath: '/', outputPath: 'assets/javascript/', uglify: true, uglifyOptions: {} })) .build(function(err) { if (err) throw err; console.log('Build complete'); });
Debug
Known issues
breakingOutput script filenames are content-hashed (SHA1), so each change produces a new file. Old files are not cleaned.
fix
Use a Metalsmith cleanup plugin or manually remove old build files before each build.
affects: >=0.1.0
deprecatedThis package has not been updated since 2020 and may have security vulnerabilities in dependencies (e.g., uglify-js).
fix
Consider using metalsmith-in-place with modern minifier (Terser) or migrate to build tools like Vite.
affects: 0.2.0
gotchaThe plugin bundles ALL script tags, including external CDN scripts. This can break sites that rely on script ordering or load cross-origin scripts.
fix
Use the data-packer='exclude' attribute on script tags you want to keep separate.
affects: >=0.1.0
gotchaInline scripts are concatenated without wrapping; variable conflicts may occur if scoping is not used.
fix
Ensure inline scripts are wrapped in IIFE or use block-scoped declarations.
affects: >=0.1.0
gotchaThe plugin relies on HTML parsing; malformed HTML (e.g., missing closing tags, unescaped attributes) can cause scripts to be missed or bundled incorrectly.
fix
Ensure your HTML is well-formed before passing to metalsmith.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: jsPacker is not a function
Trying to use import syntax with a package that exports a CommonJS factory.
fix
Use `const jsPacker = require('metalsmith-js-packer');` instead of ES import.
Error: Cannot find module 'uglify-js'
Missing dependency 'uglify-js' which is a peer dependency of metalsmith-js-packer.
fix
Run `npm install uglify-js` or `npm install --save uglify-js`.
Uncaught ReferenceError: script_variable is not defined
Order of scripts changed after bundling; a script that depended on a previous script's variable is now executed before it.
fix
Wrap code in IIFE or use modules. Alternatively, exclude scripts that must maintain order using data-packer='exclude'.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
uglify-jsrequiredJavaScript minification/uglification engine
debugoptionalDebug logging utility
Agent activity
2 hits · last 30 days
node
2
Resources
metalsmith-js-packer — npm install metalsmith-js-packer · libregistry