1. @storybook/babel-plugin-require-context-hook
Babel plugin to replicate Webpack require.context
@storybook/babel-plugin-require-context-hook
Package: @storybook/babel-plugin-require-context-hook
Created by: storybookjs
Last modified: Thu, 02 May 2024 09:13:08 GMT
Version: 1.0.1
License: MIT
Downloads: 623,502
Repository: https://github.com/storybookjs/babel-plugin-require-context-hook

Install

npm install @storybook/babel-plugin-require-context-hook
yarn add @storybook/babel-plugin-require-context-hook

babel-plugin-require-context-hook

NOTE: This is a (hopefully temporary) fork of babel-plugin-require-context-hook, which appears to be unmaintained.

Usage

In your babelrc:

"plugins": [
	"@storybook/babel-plugin-require-context-hook"
]

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

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

How it works

The register script @storybook/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 @storybook/babel-plugin-require-context-hook rewrites all calls to require.context into calls to this global function, passing in __dirname as the extra parameter.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code