{"id":21011,"library":"browser-pack-flat","title":"browser-pack-flat","description":"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.","status":"maintenance","version":"3.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/goto-bus-stop/browser-pack-flat","tags":["javascript"],"install":[{"cmd":"npm install browser-pack-flat","lang":"bash","label":"npm"},{"cmd":"yarn add browser-pack-flat","lang":"bash","label":"yarn"},{"cmd":"pnpm add browser-pack-flat","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package ships as CommonJS, so both import and require work. The module.exports is a function, so default import is safe.","wrong":"const packFlat = require('browser-pack-flat')","symbol":"default","correct":"import packFlat from 'browser-pack-flat'"},{"note":"Since v3.1.0, the main entry also serves as the plugin. Using the /plugin path still works but is unnecessary.","wrong":"browserify -p browser-pack-flat/plugin","symbol":"plugin (via browserify)","correct":"browserify -p browser-pack-flat"},{"note":"The plugin function is the default export; direct require of the package works. Use .plugin() method, not .transform().","wrong":"browserify(...).plugin(require('browser-pack-flat/plugin'), { ... })","symbol":"require as packer","correct":"browserify(...).plugin(packFlat, { ... })"},{"note":"The packer expects browser-unpack JSON on stdin, not a raw bundle. Must pipe through browser-unpack first.","wrong":"browserify app.js | browser-pack-flat","symbol":"CLI usage via browser-unpack","correct":"browserify app.js | browser-unpack | browser-pack-flat"}],"quickstart":{"code":"const browserify = require('browserify');\nconst packFlat = require('browser-pack-flat');\nconst fs = require('fs');\n\nconst b = browserify({ entries: './app.js' });\nb.plugin(packFlat, { iife: false });\nb.bundle()\n  .pipe(fs.createWriteStream('bundle.js'))\n  .on('finish', () => console.log('Bundled!'));","lang":"javascript","description":"Demonstrates using browser-pack-flat as a browserify plugin with IIFE removal, piping output to a file."},"warnings":[{"fix":"Ensure modules don't rely on interleaved execution; test thoroughly.","message":"Modules are executed fully one after another, not inline. This can change execution order vs Node.js and default browserify.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a different bundling strategy if you need code splitting.","message":"Does not work with factor-bundle; output splitting is incompatible.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid wrapping require; use inline requires only.","message":"Modules that wrap require() (e.g., with custom caching or instrumentation) will break.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need inlining of dynamic requires, pin to earlier version.","message":"In v3.4.0, conditional and lazy require() calls are no longer inlined; they remain as function calls.","severity":"breaking","affected_versions":">=3.4.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use require('browser-pack-flat') instead of '/plugin'.","cause":"Old v3.0.x path; main entry acts as plugin since v3.1.0.","error":"Error: Cannot find module 'browser-pack-flat/plugin'"},{"fix":"Pipe through browser-unpack first: browserify app.js | browser-unpack | browser-pack-flat","cause":"Input is not browser-unpack JSON but raw JavaScript bundle.","error":"Unexpected token: punc ())"},{"fix":"Use .plugin(packFlat) or .plugin(require('browser-pack-flat'))","cause":"Forgetting to call .plugin() with the function; passing string instead.","error":"TypeError: browserify(...).plugin is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}