brfs-babel
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript maintenance
A browserify transform that inlines static file contents at build time, similar to brfs but built on top of Babel for ES2015+ support. Version 2.0.0 is the current stable release. It handles ES2015 import syntax, supports fs.readFileSync and fs.readdirSync, and evaluates path.join/path.resolve statically. Unlike brfs, it works with Babel AST for cleaner output and source maps, but is experimental and has limitations (e.g., no support for dynamic expressions or inline CommonJS require).
Common errors
error Error: Cannot find module 'brfs-babel' ↓
cause brfs-babel not installed globally or locally.
fix
Run
npm install --save-dev brfs-babel in project directory. error fs.readFileSync(...): path must be a string or Buffer ↓
cause Dynamic variable used in file path that brfs-babel cannot evaluate.
fix
Use static path like path.join(__dirname, 'file.txt').
error Error: Could not transform: ... ↓
cause brfs-babel encountered unsupported syntax like require('fs').readFileSync.
fix
Use ES2015 import { readFileSync } from 'fs' instead.
Warnings
gotcha Only fs.readFileSync and fs.readdirSync are supported, not fs.writeFileSync or fs.statSync. ↓
fix Use brfs for more fs methods or implement custom transform.
gotcha Dynamic expressions (e.g., __dirname + variable) are not evaluated statically, causing runtime errors. ↓
fix Use only static string paths with path.join or path.resolve.
gotcha Inline CommonJS require('fs').readFileSync is not supported; only imported fs works. ↓
fix Use ES2015 import syntax for fs.
deprecated Package is experimental and no longer actively maintained. brfs is more stable and widely used. ↓
fix Consider using brfs or browserify-plugin-fs for production.
Install
npm install brfs-babel yarn add brfs-babel pnpm add brfs-babel Quickstart
// Install: npm install brfs-babel
// In your browserify build command:
// browserify index.js -t brfs-babel
// Example file: index.js
import { readFileSync } from 'fs';
import { join } from 'path';
const src = readFileSync(join(__dirname, 'hello.txt'), 'utf8');
console.log(src);
// With hello.txt containing "Hello, World!", after transform:
// import { join } from 'path';
// const src = 'Hello, World!';
// console.log(src);