A Babel plugin that replicates Webpack's `require.context` functionality for use with `babel-register`. Version 1.0.0 is stable; the plugin rewrites `require.context()` calls to use a global polyfill that must be registered at runtime via `require('babel-plugin-require-context-hook/register')()`. It depends on `@babel/core ^7.2.2`. This is a minimal, focused alternative to full Webpack configurations for projects needing dynamic require in Node.js.
npm install babel-plugin-require-context-hook-babel7Verified import paths — ran on the pinned version, not inferred.
Demonstrates setup: add plugin to .babelrc, register polyfill at entry point, then use require.context with three arguments.
Call require('babel-plugin-require-context-hook/register')() at the very top of your entry file, before requiring any module that uses require.context.Always provide all three arguments: require.context(directory, useSubdirectories, regExp). If you don't care about a filter, use /^./.
Use the short plugin name: "require-context-hook" without the 'babel-plugin-' prefix.
Add require('babel-plugin-require-context-hook/register')() at the very top of your entry file, before any other require calls.Provide a third argument to require.context, e.g., require.context('./', true, /\.js$/).