Babel plugin that transforms eval() calls containing string literals by parsing and compiling the string content at transform time
Overall
score
98%
A Babel plugin that automatically maps Node.js built-in module imports to browser-compatible polyfills.
When writing code that needs to run in both Node.js and browser environments, developers often need to use polyfills for Node.js built-in modules. This plugin automates the process by transforming import statements for Node.js built-ins to use appropriate polyfill packages.
import fs from 'fs' to import fs from 'browserify-fs' @testimport { readFile } from 'fs' to import { readFile } from 'browserify-fs' @testimport path from 'path' to import path from 'path-browserify' @testimport crypto from 'crypto' to import crypto from 'crypto-browserify' @testimport fs from 'node:fs' to import fs from 'browserify-fs' (strips the node: prefix) @testimport path from 'node:path' to import path from 'path-browserify' @testimport React from 'react' @testimport { util } from './my-utils' @test@generates
/**
* Creates a Babel plugin that transforms Node.js built-in imports to polyfills
* @param {Object} babel - The Babel instance
* @param {Object} babel.types - Babel types helper (commonly aliased as 't')
* @returns {Object} Babel plugin object with visitor pattern
*/
export default function (babel) {
const { types: t } = babel;
return {
visitor: {
ImportDeclaration(path) {
// Plugin implementation
}
}
};
}Provides the core Babel transformation API and plugin infrastructure.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-evaldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10