Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-require-context-hook

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-require-context-hook

Babel plugin to replicate Webpack require.context

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
238K
increased by14.23%
Maintainers
1
Weekly downloads
 
Created

What is babel-plugin-require-context-hook?

The babel-plugin-require-context-hook package is a Babel plugin that allows you to use Webpack's require.context in environments where it is not natively available, such as in Node.js or Jest. This can be particularly useful for testing or server-side rendering scenarios.

What are babel-plugin-require-context-hook's main functionalities?

Mocking require.context in Node.js

This feature allows you to mock Webpack's require.context in a Node.js environment. By registering the hook, you can use require.context to dynamically require files based on a pattern.

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

const context = require.context('./path/to/files', false, /\.js$/);
context.keys().forEach(context);

Using require.context in Jest tests

This feature allows you to use require.context in Jest tests. By registering the hook, you can dynamically require test files based on a pattern, making it easier to manage and run tests.

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

// In your Jest test file
const context = require.context('../src/components', true, /\.test\.js$/);
context.keys().forEach(context);

Other packages similar to babel-plugin-require-context-hook

Keywords

FAQs

Package last updated on 06 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc