{"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,"search_vec":"'2020':33 '3.5.0':26 'browser':2,56 'browser-pack':55 'browser-pack-flat':1 'browserifi':5 'bundl':8,37,86 'call':45 'certain':79 'cost':70 'current':22 'default':54 'differ':75 'differenti':34 'drastic':35 'e.g':81 'ecmavers':89 'elimin':17 'execut':40,73 'factor':85 'factor-bundl':84 'fals':96 'flat':4 'flatten':50 'function':64 'iif':92,95 'incompat':77 'javascript':97 'maintain':27 'major':30 'modul':9,51,63 'option':90 'order':74 'overhead':41 'pack':3,57 'pattern':80 'per':62 'per-modul':61 'plugin':6 'potenti':72 'reduc':36 'refer':48 'releas':31 'remov':59,93 'requir':19,44,83 'rewrit':43 'rollup':16 'runtim':20,67 'scope':13,52 'similar':14 'sinc':32 'singl':12 'size':38 'sporad':28 'stabl':23 'support':87 'unlik':53 'variabl':47 'version':24 'via':94 'wrap':82 'wrapper':21,65","created_at":"2026-04-27T16:57:37.851216+00:00","updated_at":"2026-04-27T16:57:37.851216+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/goto-bus-stop/browser-pack-flat","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/browser-pack-flat","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-26","install_tag":null}}