Babel Transform for bit-imports and bit-bundler
raw JSON →babel-bits is an npm package designed to integrate Babel 6 transformations within the bit-imports and bit-bundler ecosystems. It acts as a handler for JavaScript files, allowing them to be transpiled during the import or bundling process. The package, currently at its last stable version v1.0.1 released in 2017, wraps `babel-core` (v6) along with `babel-preset-es2015` and `babel-preset-react` as default configurations. The project and its parent `bit-imports` and `bit-bundler` dependencies appear to be abandoned, with no significant updates or maintenance since 2017. Key differentiators included its deep integration with the specific module loading and bundling mechanisms of `bit-imports` and `bit-bundler`, offering a pre-configured, albeit outdated, Babel setup for those systems. It does not follow a regular release cadence and is effectively end-of-life.
Common errors
error Error: Cannot find module '@babel/core' or similar errors referencing new Babel packages. ↓
babel-core, babel-preset-es2015, and babel-preset-react (all ^6.0.0) are installed as direct dependencies. Do NOT install @babel/core or other @babel/ scoped packages. error ReferenceError: regeneratorRuntime is not defined ↓
regenerator-runtime (npm install regenerator-runtime) and import it once at the top of your application's entry file: require('regenerator-runtime/runtime'); or ensure it's loaded via a script tag in the browser. Warnings
breaking babel-bits relies exclusively on Babel 6 (specifically `babel-core@^6.0.0`) and its associated presets. It is fundamentally incompatible with Babel 7+ due to significant API changes and package renames. Attempting to use it with a modern Babel setup will lead to errors. ↓
deprecated The entire babel-bits, bit-imports, and bit-bundler ecosystem is considered abandoned. There have been no code updates or maintenance since 2017. Using this package in new projects is strongly discouraged, and existing projects should plan for migration. ↓
gotcha When using Babel 6 (as babel-bits does) for generator functions (e.g., `async/await`), you must manually include `regeneratorRuntime` in your application's global scope. Babel 6 does not automatically polyfill this, leading to runtime errors. ↓
Install
npm install babel-bits yarn add babel-bits pnpm add babel-bits Imports
- babel-bits handler string wrong
import { handler } from 'babel-bits'; /* Not exposed for direct import */correctbitimports.plugin("js", { transform: { handler: "babel-bits", options: { /* ... */ } } }); - Options for Babel wrong
import { configure } from 'babel-bits';correctbitimports.plugin("js", { transform: { handler: "babel-bits", options: { sourceMaps: "inline", presets: ["es2015", "react"] } } });
Quickstart
const bitimports = require('bit-imports');
// Configure bit-imports to use babel-bits for JavaScript transformations
bitimports.plugin('js', {
transform: {
handler: 'babel-bits', // Specify babel-bits as the transformation handler
options: {
sourceMaps: 'inline', // Enable inline source maps for debugging
presets: ['es2015', 'react'] // Configure default Babel 6 presets
}
}
});
// Example of how bit-imports might then load a module
// In a real application, you would load your main application file here
// const myModule = bitimports.load('./src/main.js');
// console.log('bit-imports configured with babel-bits:', myModule);
console.log('babel-bits is configured via bit-imports plugin. No direct module interaction typically occurs.');
console.log('Ensure babel-core, babel-preset-es2015, and babel-preset-react are installed alongside.');