JSPM

babel-plugin-require-context-hook-babel7

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5734
  • Score
    100M100P100Q139082F
  • License MIT

Babel plugin to replicate Webpack require.context

Package Exports

  • babel-plugin-require-context-hook-babel7

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-require-context-hook-babel7) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-plugin-require-context-hook

Usage

babelrc:

"plugins": [
    "require-context-hook"
]

Wherever you configure babel-register (your source file, a register script, etc):

require('babel-plugin-require-context-hook/register')();

How it works

The register script babel-plugin-require-context-hook/register implements the function require.context with an extra parameter-- the directory in which the calling file resides-- and places that function on the global scope.

The Babel plugin babel-plugin-require-context-hook rewrites all calls to require.context into calls to this global function, passing in __dirname as the extra parameter.