{"id":12890,"library":"bit-bundler-splitter","title":"Bit-Bundler Splitter Plugin","description":"bit-bundler-splitter is a plugin for the bit-bundler module bundler, designed to segment application code into smaller, optimized bundles, often referred to as 'bundle shards.' Its primary use case is to separate third-party vendor modules from application-specific code, leveraging browser caching for improved performance and reduced network traffic for returning visitors. The current stable version is 7.0.0, indicating continued development despite a non-fixed release cadence. Key differentiators include its flexible matching rules, powered by `roolio`, which allow granular control over module placement based on path, filename, or other properties. It automatically generates a `common` bundle to prevent module duplication across different shards and a `loader` bundle to manage the correct loading order of bundles in the browser. Furthermore, it supports building a sophisticated bundle tree for better dependency resolution and includes mechanisms for detecting circular references between generated bundles, contributing to a robust bundling strategy.","status":"active","version":"7.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/MiguelCastillo/bit-bundler-splitter","tags":["javascript","bit-bundler","bit-bundler-plugin"],"install":[{"cmd":"npm install bit-bundler-splitter","lang":"bash","label":"npm"},{"cmd":"yarn add bit-bundler-splitter","lang":"bash","label":"yarn"},{"cmd":"pnpm add bit-bundler-splitter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a plugin for bit-bundler and requires it to operate.","package":"bit-bundler","optional":false}],"imports":[{"note":"The module exports a single function as its default. It is primarily a CommonJS module, so use `require` for direct access.","wrong":"import { splitBundle } from 'bit-bundler-splitter';\nconst { splitBundle } = require('bit-bundler-splitter');","symbol":"splitBundle","correct":"const splitBundle = require('bit-bundler-splitter');"},{"note":"The most common and recommended usage is to provide the module name as a string within `bit-bundler`'s `bundler` plugin array. `bit-bundler` handles the internal resolution, which also future-proofs against potential changes in direct module export.","wrong":"[require('bit-bundler-splitter'), { /* config */ }]","symbol":"Plugin Reference (bit-bundler config)","correct":"['bit-bundler-splitter', { /* config */ }]"}],"quickstart":{"code":"// First, install necessary packages:\n// npm install --save-dev bit-bundler bit-bundler-splitter bit-loader-babel\n\nconst Bitbundler = require('bit-bundler');\nconst splitBundle = require('bit-bundler-splitter');\n\n// Create dummy files for a runnable example:\n// src/main.js: console.log('Main application loaded'); require('./renderer/component');\n// src/renderer/component.js: console.log('Renderer component loaded'); require('lodash');\n// node_modules/lodash/lodash.js (or any other module)\n\nBitbundler.bundle({\n  src: 'src/main.js',\n  dest: 'dist/main.js'\n}, {\n  loader: [\n    'bit-loader-babel' // Example loader, often used for modern JS transpilation\n  ],\n  bundler: [\n    [splitBundle, [\n      { \n        name: 'vendor', \n        dest: 'dist/vendor.js', \n        match: ['/bower_components/', '/node_modules/'] // Matches modules in these paths\n      },\n      { \n        name: 'renderer', \n        dest: 'dist/renderer.js', \n        match: '/src/renderer/' // Matches modules in the src/renderer path\n      }\n    ]]\n  ]\n}).then(() => {\n  console.log('Bundling complete! Check dist/main.js, dist/vendor.js, dist/renderer.js');\n  console.log('To run: cat dist/vendor.js dist/renderer.js dist/main.js | node');\n}).catch(err => {\n  console.error('Bundling failed:', err);\n});","lang":"javascript","description":"This quickstart demonstrates how to configure `bit-bundler-splitter` as a plugin within `bit-bundler` to split vendor and renderer-specific modules into separate output files, including basic error handling."},"warnings":[{"fix":"Refactor plugin configurations from `['bit-bundler-splitter', 'my-name', {...}]` to `['bit-bundler-splitter', { name: 'my-name', ... }]`.","message":"The `bit-bundler-splitter` plugin, as of v4.0.0, no longer accepts a `name` as the first argument directly. All configuration, including the bundle name, must now be provided via a single options object.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Carefully review the `v5.0.0` release notes and documentation to update your bundle configuration, paying close attention to bundle loading, tree construction, and how circular references are handled in your specific setup.","message":"Version 5.0.0 introduced a significant rewrite of `bit-bundler-splitter`, including a new bundle loader, support for building a bundle tree, and enhanced detection of circular references between bundles. This may require review and adjustments to existing bundle configurations due to potential architectural changes in how bundles are loaded and dependencies resolved.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Upgrade `bit-bundler-splitter` to `v5.0.1` or higher. Ensure all necessary Babel peer dependencies (e.g., `@babel/core`, `@babel/preset-env`) are explicitly installed in your project's `devDependencies`.","message":"A fix for 'not having the proper babel dependencies' was released in v5.0.1. If you are using `bit-loader-babel` alongside `bit-bundler-splitter`, older versions might lead to build failures due to missing Babel-related peer dependencies.","severity":"gotcha","affected_versions":"<5.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Configure `bit-bundler-splitter` using an options object that includes a `name` property: `['bit-bundler-splitter', { name: 'vendor', dest: 'dist/vendor.js', match: [...] }]`.","cause":"Attempting to use the pre-v4 API by passing the bundle name as the first argument, or omitting the required options object entirely.","error":"Error: Plugin configuration for 'bit-bundler-splitter' is invalid. The 'name' property is missing or not an object."},{"fix":"Use CommonJS `require` for the default export: `const splitBundle = require('bit-bundler-splitter');`","cause":"Attempting to import `bit-bundler-splitter` using ES module syntax (`import`) or incorrectly destructuring its CommonJS `require` call, when the module exports a single function as its default.","error":"TypeError: (0 , _bitBundlerSplitter.default) is not a function"},{"fix":"Install the required Babel packages as dev dependencies: `npm install --save-dev @babel/core @babel/preset-env` and ensure `bit-bundler-splitter` is at least `v5.0.1`.","cause":"Missing essential Babel-related peer dependencies when `bit-loader-babel` is utilized in conjunction with `bit-bundler-splitter` within your `bit-bundler` setup.","error":"Error: Module build failed (from ../node_modules/bit-loader-babel/index.js): Error: Cannot find module '@babel/core'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}