# promisify-loader-runner

> a promisify wrapper of `loader-runner`

Latest version **1.0.1** (published 2023-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install promisify-loader-runner
pnpm add promisify-loader-runner
yarn add promisify-loader-runner
bun add promisify-loader-runner
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-11-24 |
| First published | 2023-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SonOfMagic |
| Maintainers | icebreaker |
| Keywords | webpack, loader, loader-runner, promisify |

## Links

- npm: https://www.npmjs.com/package/promisify-loader-runner
- Repository: https://github.com/sonofmagic/utils
- Homepage: https://github.com/sonofmagic/utils/tree/main/packages/promisify-loader-runner#readme
- Issues: https://github.com/sonofmagic/utils/issues
- npm.io page: https://npm.io/package/promisify-loader-runner

## Dependencies (2)

- [loader-runner](https://npm.io/package/loader-runner.md) ^4.3.0
- [@types/loader-runner](https://npm.io/package/@types/loader-runner.md) ^2.2.8

## 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.1 (latest) — 2023-11-24
- 1.0.0 — 2023-06-16

## README

# promisify-loader-runner

This is a promisify method of `loader-runner` <https://github.com/webpack/loader-runner>

and you can use both `promisify` or `callback` calling style

## Usage

### Promise

```js
import { runLoaders } from "promisify-loader-runner";

try {
  const result = await runLoaders({
    resource: "/abs/path/to/file.txt?query",
    loaders: ["/abs/path/to/loader.js?query"],
    context: { minimize: true },
    processResource: (loaderContext, resourcePath, callback) => { ... },
    readResource: fs.readFile.bind(fs)
  })
} catch (err){
  // err: Error?
}
```

### Callback (original way)

```js
import { runLoaders } from "promisify-loader-runner";

runLoaders({
 resource: "/abs/path/to/file.txt?query",
 // String: Absolute path to the resource (optionally including query string)

 loaders: ["/abs/path/to/loader.js?query"],
 // String[]: Absolute paths to the loaders (optionally including query string)
 // {loader, options}[]: Absolute paths to the loaders with options object

 context: { minimize: true },
 // Additional loader context which is used as base context

 processResource: (loaderContext, resourcePath, callback) => { ... },
 // Optional: A function to process the resource
 // Must have signature function(context, path, function(err, buffer))
 // By default readResource is used and the resource is added a fileDependency

 readResource: fs.readFile.bind(fs)
 // Optional: A function to read the resource
 // Only used when 'processResource' is not provided
 // Must have signature function(path, function(err, buffer))
 // By default fs.readFile is used
}, function(err, result) {
 // err: Error?

 // result.result: Buffer | String
 // The result
 // only available when no error occurred

 // result.resourceBuffer: Buffer
 // The raw resource as Buffer (useful for SourceMaps)
 // only available when no error occurred

 // result.cacheable: Bool
 // Is the result cacheable or do it require reexecution?

 // result.fileDependencies: String[]
 // An array of paths (existing files) on which the result depends on

 // result.missingDependencies: String[]
 // An array of paths (not existing files) on which the result depends on

 // result.contextDependencies: String[]
 // An array of paths (directories) on which the result depends on
})
```

---
_Source: https://npm.io/package/promisify-loader-runner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
