# node-plugin-require-context

> nodejs plugin like webpack require-context.

Latest version **1.0.0** (published 2020-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-plugin-require-context
pnpm add node-plugin-require-context
yarn add node-plugin-require-context
bun add node-plugin-require-context
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-12-07 |
| First published | 2020-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Condor Hero |
| Maintainers | condorhero |
| Keywords | require-context, nodejs-require-context, webpack-require-context |

## Links

- npm: https://www.npmjs.com/package/node-plugin-require-context
- Repository: https://github.com/condorheroblog/node-plugin-require-context
- Homepage: https://github.com/condorheroblog/node-plugin-require-context#readme
- Issues: https://github.com/condorheroblog/node-plugin-require-context/issues
- npm.io page: https://npm.io/package/node-plugin-require-context

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-12-07

## README

# node-plugin-require-context

[![NPM version](https://img.shields.io/npm/v/node-plugin-require-context)](https://www.npmjs.com/package/node-plugin-require-context)
![Downloads](https://img.shields.io/npm/dw/node-plugin-require-context)
[![License](https://img.shields.io/npm/l/node-plugin-require-context)](./LICENSE)

> nodejs plugin like webpack require-context.

Inspiration from [ webpack's require.context](https://webpack.js.org/guides/dependency-management/#requirecontext)，You can batch import files in NodeJs.


## Usage

*install*

```npm
npm install --save-dev node-plugin-require-context
```

*Example*

```js
const requireContext = require('node-plugin-require-context');
const context = requireContext('./', true, /\.js$/, __dirname);

context.keys().forEach(modulePath => {
    /* get module */
    context(modulePath);
});
```

## Options

`requireContext ( directory, useSubdirectories, regExp, rootPath, fn )`  

- `directory`
>  search dir, you can input like './' or '../' and so on, Required parameter.

- `useSubdirectories`

> `true` will search all child file; `false` only search current dir, Required parameter.

- `regExp`

> RegExp match; match the files you need,Required parameter.

- `rootPath`
> this is indispensable，The fixed value is `__dirname`, Required parameter.

- `fn`
> A callback function; when matching to the correct file will call it,Optional parameters

## API

The `context` function has 2 properties: resolve and keys.

- resolve is a function and when passed in the module relative path and returns absolute path.
- keys is a function that returns an array of all possible requests that the context module can handle.

---
_Source: https://npm.io/package/node-plugin-require-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
