Registry / devops / browser-pack-flat

browser-pack-flat

JSON →
library3.5.0jsnpmunverified

Browserify plugin that bundles modules into a single scope, similar to Rollup, eliminating the require runtime wrapper. Current stable version is 3.5.0. Maintained sporadically; no major release since 2020. Differentiator: drastically reduces bundle size and execution overhead by rewriting require() calls to variable references and flattening module scopes. Unlike default browser-pack, it removes the per-module function wrapper and runtime, at the cost of potential execution order differences and incompatibility with certain patterns (e.g., wrapped require, factor-bundle). Supports an ecmaVersion option and IIFE removal via iife:false.

npm install browser-pack-flat
INSTALL
IMPORT
SIG · BROWSER-PACK-FLAT
B
browser-pack-flat
devopsjavascriptv3.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import packFlat from 'browser-pack-flat'
const packFlat = require('browser-pack-flat')
Package ships as CommonJS, so both import and require work. The module.exports is a function, so default import is safe.
plugin (via browserify)
browserify -p browser-pack-flat
browserify -p browser-pack-flat/plugin
Since v3.1.0, the main entry also serves as the plugin. Using the /plugin path still works but is unnecessary.
require as packer
browserify(...).plugin(packFlat, { ... })
browserify(...).plugin(require('browser-pack-flat/plugin'), { ... })
The plugin function is the default export; direct require of the package works. Use .plugin() method, not .transform().
CLI usage via browser-unpack
browserify app.js | browser-unpack | browser-pack-flat
browserify app.js | browser-pack-flat
The packer expects browser-unpack JSON on stdin, not a raw bundle. Must pipe through browser-unpack first.

Demonstrates using browser-pack-flat as a browserify plugin with IIFE removal, piping output to a file.

const browserify = require('browserify'); const packFlat = require('browser-pack-flat'); const fs = require('fs'); const b = browserify({ entries: './app.js' }); b.plugin(packFlat, { iife: false }); b.bundle() .pipe(fs.createWriteStream('bundle.js')) .on('finish', () => console.log('Bundled!'));
Debug
Known issues
gotchaModules are executed fully one after another, not inline. This can change execution order vs Node.js and default browserify.
fix
Ensure modules don't rely on interleaved execution; test thoroughly.
affects: >=1.0.0
gotchaDoes not work with factor-bundle; output splitting is incompatible.
fix
Use a different bundling strategy if you need code splitting.
affects: >=1.0.0
gotchaModules that wrap require() (e.g., with custom caching or instrumentation) will break.
fix
Avoid wrapping require; use inline requires only.
affects: >=1.0.0
breakingIn v3.4.0, conditional and lazy require() calls are no longer inlined; they remain as function calls.
fix
If you need inlining of dynamic requires, pin to earlier version.
affects: >=3.4.0
Errors
Common errors & fixes
Error: Cannot find module 'browser-pack-flat/plugin'
Old v3.0.x path; main entry acts as plugin since v3.1.0.
fix
Use require('browser-pack-flat') instead of '/plugin'.
Unexpected token: punc ())
Input is not browser-unpack JSON but raw JavaScript bundle.
fix
Pipe through browser-unpack first: browserify app.js | browser-unpack | browser-pack-flat
TypeError: browserify(...).plugin is not a function
Forgetting to call .plugin() with the function; passing string instead.
fix
Use .plugin(packFlat) or .plugin(require('browser-pack-flat'))
Upgrade
Version history
3.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
browser-pack-flat — npm install browser-pack-flat · libregistry