{"id":15543,"library":"bit-bundler-extractsm","title":"Bit-Bundler Source Map Extraction Plugin","description":"bit-bundler-extractsm is a specialized plugin for the `bit-bundler` ecosystem, designed to manage source maps during the bundling process. Its primary function is to extract inline or generated source maps from bundled JavaScript files and write them to separate, dedicated `.map` files, typically alongside their corresponding JavaScript output. As of version `2.1.4`, it offers stable functionality for `bit-bundler` users. While its release cadence is not strictly defined, it appears to be actively maintained for bug fixes and compatibility, with recent updates addressing specific edge cases. A key differentiator is its deep integration with `bit-bundler`'s plugin architecture, allowing granular control over source map extraction, including the ability to entirely remove source maps from bundles or to manage them differently across various bundle splits. This makes it essential for optimizing production builds by separating source map files, preventing them from being included in the main application bundle.","status":"maintenance","version":"2.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/MiguelCastillo/bit-bundler-extractsm","tags":["javascript","bit-bundler","bit-bundler-plugin"],"install":[{"cmd":"npm install bit-bundler-extractsm","lang":"bash","label":"npm"},{"cmd":"yarn add bit-bundler-extractsm","lang":"bash","label":"yarn"},{"cmd":"pnpm add bit-bundler-extractsm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a plugin for bit-bundler and requires the core bundler to operate.","package":"bit-bundler","optional":false},{"reason":"Often used in conjunction to generate source maps which bit-bundler-extractsm then processes.","package":"bit-bundler-minifyjs","optional":true}],"imports":[{"note":"The core `bit-bundler` library is typically imported via CommonJS `require()` in environments where this plugin is most often used, as shown in the README examples.","wrong":"import Bitbundler from 'bit-bundler';","symbol":"Bitbundler","correct":"var Bitbundler = require(\"bit-bundler\");"},{"note":"`bit-bundler-extractsm` is registered as a plugin by its package name string within `bit-bundler`'s configuration array, not via a direct JavaScript import or require statement into user code.","wrong":"import { extractsm } from 'bit-bundler-extractsm';","symbol":"Plugin Registration String","correct":"bundler: [\"bit-bundler-extractsm\"]"},{"note":"While the module can technically be `require()`d, `bit-bundler-extractsm` is almost exclusively used as a named plugin string within `bit-bundler`'s configuration rather than directly invoking functions from `extractsmModule` in user code.","wrong":"import * as extractsmModule from 'bit-bundler-extractsm';","symbol":"Direct Module Reference (Rare)","correct":"const extractsmModule = require('bit-bundler-extractsm');"}],"quickstart":{"code":"const Bitbundler = require(\"bit-bundler\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\n\n// Create a dummy in.js file for the example\nconst inJsContent = `\n// in.js\nconsole.log('Hello from in.js');\nconst add = (a, b) => a + b;\nconsole.log('Sum:', add(1, 2));\n// This line is often generated by tools like Babel or TypeScript, or explicitly added by minifiers.\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluLmpzIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciLCJhZGQiLCJhIiwiYiJdLCJtYXBwaW5ncyI6IkFBQUE7QUFDQUEsUUFBQUMsR0FBRCxDQUFLLGtCQUFMLENBQUw7QUFDQSxNQUFNQyxHQUFHLENBQUNDLEVBQUQsRUFBU0MsQ0FBVCxDQUFELEdBQWdCRCxDQUFDLEdBQUVDLENBQXJCO0FBQ0FILFFBQUFDLGdBQWdCLENBQUNFLFdBQVdDLENBQUMsQ0FBQyxDQUFFLENBQUMsQ0FBRCxDQUFZLENBQVAsQ0FBckI7QUFDQTtBQUxBIiwic291cmNlc0NvbnRlbnQiOlsiLy8gaW4uanNcbmNvbnNvbGUubG9nKCdIZWxsbyBmcm9tIGluLmpzJyk7XG5jb25zdCBhZGQgPSAocmEsIGIpID0+IGEgKyBiO1xuY29uc29sZS5sb2coJ1N1bTogJywgYWRkKDEsIDIpKTtcbi8vIHRoaXMgaW5saW5lIHNvdXJjZW1hcCBpcyBmb3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcywgbm90gCBhIGNhbm9uaWNhbCBzb3VyY2VtYXAgZm9ybWF0XG4jIyMgc291cmNlTWFwZmluZ1VSTA1pbi5qcy5tYXAgYnkgYmFzZTY0IGVuY29kaW5nIGEgZHVubXkgc291cmNlbWFwXG4ifV0sImZpbGUiOiJpbi5qcyJ9\n`;\nconst inJsPath = path.join(__dirname, 'in.js');\nfs.writeFileSync(inJsPath, inJsContent.trim());\n\nconst outJsPath = path.join(__dirname, 'out.js');\nconst outMapPath = path.join(__dirname, 'out.js.map');\n\n// Clean up previous outputs if they exist\nif (fs.existsSync(outJsPath)) fs.unlinkSync(outJsPath);\nif (fs.existsSync(outMapPath)) fs.unlinkSync(outMapPath);\n\nconsole.log('Starting bundling process...');\nBitbundler.bundle({\n  src: inJsPath,\n  dest: outJsPath\n}, {\n  bundler: [\n    // bit-bundler-minifyjs is often used to generate the source map that extractsm will then process\n    \"bit-bundler-minifyjs\",\n    \"bit-bundler-extractsm\"\n  ]\n}).then(() => {\n  console.log(`Bundle created at ${outJsPath}`);\n  console.log(`Source map extracted to ${outMapPath}`);\n  console.log('Verification: out.js should reference out.js.map, and out.js.map should exist.');\n  \n  // Clean up dummy in.js after bundling\n  fs.unlinkSync(inJsPath);\n}).catch(err => {\n  console.error('Bundling failed:', err);\n  // Ensure cleanup even on error\n  if (fs.existsSync(inJsPath)) fs.unlinkSync(inJsPath);\n  if (fs.existsSync(outJsPath)) fs.unlinkSync(outJsPath);\n  if (fs.existsSync(outMapPath)) fs.unlinkSync(outMapPath);\n});\n\n// To run this example:\n// 1. Ensure you have Node.js installed.\n// 2. npm install bit-bundler bit-bundler-minifyjs bit-bundler-extractsm\n// 3. Save the code above as 'bundle.js'\n// 4. Run: node bundle.js\n","lang":"javascript","description":"This example demonstrates how to use `bit-bundler-extractsm` with `bit-bundler` and `bit-bundler-minifyjs` to bundle `in.js` into `out.js` and extract its source map into a separate `out.js.map` file."},"warnings":[{"fix":"Ensure that your `Bitbundler.bundle` call always specifies a `dest` path for the main output bundle. Upgrade to version `2.1.2` or higher to fix this bug automatically.","message":"When `bit-bundler-extractsm` is used without a `dest` option for the main bundle, it might incorrectly generate sourcemap files named `null.map` in `process.cwd()`.","severity":"gotcha","affected_versions":"<2.1.2"},{"fix":"Verify that a plugin preceding `bit-bundler-extractsm` in the `bundler` array (e.g., `bit-bundler-minifyjs`) is configured to generate source maps. Consult the documentation for other `bit-bundler` plugins to ensure they are outputting source maps.","message":"`bit-bundler-extractsm` requires another bundler plugin (like `bit-bundler-minifyjs`) to actually generate source maps in the first place. If no source maps are being produced by prior steps in the pipeline, `extractsm` will have nothing to extract.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"To remove all source maps, use `['bit-bundler-extractsm', false]`. For specific bundle splits, provide an object like `['bit-bundler-extractsm', { vendor: false }]` where `vendor` is the name of the bundle split.","message":"To remove sourcemaps from a bundle or a specific bundle split, `bit-bundler-extractsm` must be configured with `false` or an object specifying `false` for named splits. Misconfiguration can lead to unexpected source map generation or removal.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure that `Bitbundler.bundle` is always called with a valid `dest` option, like `dest: 'out.js'`. For `bit-bundler-extractsm` versions prior to `2.1.2`, this was a known bug; upgrading to `2.1.2` or newer resolves the underlying issue.","cause":"The `bit-bundler` bundle operation was executed without a `dest` (destination) file path specified, causing `bit-bundler-extractsm` to misinterpret the output target.","error":"Sourcemap files named 'null.map' generated in current working directory."},{"fix":"Confirm that your bundling pipeline includes a plugin that generates source maps and that `bit-bundler-extractsm` is placed after it in the `bundler` array. Also, ensure `bit-bundler-extractsm` is not configured to `false` for the affected bundle or split.","cause":"Either no upstream `bit-bundler` plugin (e.g., `bit-bundler-minifyjs`, Babel plugin) is configured to produce source maps, or `bit-bundler-extractsm` is explicitly disabled in the bundler configuration.","error":"Source map file not generated or extracted (e.g., 'out.js.map' is missing)."}],"ecosystem":"npm"}