https://github.com/lukeed/loadr
Quickly attach multiple ESM Loaders and/or Require Hooks together but without the repetitive `--experimental-loader` and/or `--require` Node flags
https://github.com/lukeed/loadr
Last synced: 5 months ago
JSON representation
Quickly attach multiple ESM Loaders and/or Require Hooks together but without the repetitive `--experimental-loader` and/or `--require` Node flags
- Host: GitHub
- URL: https://github.com/lukeed/loadr
- Owner: lukeed
- License: mit
- Created: 2021-08-17T07:04:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-28T00:02:57.000Z (over 4 years ago)
- Last Synced: 2024-11-08T08:08:18.368Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 49
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license
Awesome Lists containing this project
- awesome-list - loadr - -experimental-loader` and/or `--require` Node flags | lukeed | 33 | (JavaScript)
README
Quickly attach multiple ESM Loaders and/or Require Hooks together
but without the repetitive `--experimental-loader` and/or `--require` Node flags
## Features
* Extremely lightweight
* Easily chain multiple [ESM Loaders](https://nodejs.org/api/esm.html#esm_loaders) together†
* Interleave additional [`--require` hooks](https://nodejs.org/api/cli.html#cli_r_require_module) at the same time
* Command spawns as a `ChildProcess`, forwarding the current `process.env` context
> † The ESM Loader API is still **experimental** and will change in the future.
## Install
```
$ npm install --save-dev loadr
```
## Example
***Before***
```sh
$ node --require dotenv/config \
--experimental-loader ts-node/esm \
--experimental-loader ./tests/loader.mjs \
server/index.mjs
```
***After***
```sh
$ loadr -- node server/index.mjs
```
```js
// loadr.mjs
export const loaders = [
'ts-node/esm',
'./tests/loader.mjs',
]
export const registers = [
'dotenv/config',
]
```
## Usage
```sh
# Run `npm test` using the `loadr.mjs` configuration file
$ loadr -- npm test
# Run `npm test` using custom `loadr.custom.js` file
$ loadr -c loadr.custom.js -- npm test
# Run `node server.mjs` w/o system bell
$ loadr -q -- node server.mjs
```
## CLI
The `loadr` binary expects the following usage:
```sh
$ loadr [options] --
```
> **Important:** The `--` is required! It separates your `command` from your `loadr` arguments.
Please run `loadr --help` for additional information.
## Configuration
Unless specified via the `-c` or `--config` CLI arguments, `loadr` looks for a `loadr.mjs` configuration file in the current working directory – aka `process.cwd()`.
### loaders
Type: `string[]`
A list of files and/or modules to be added as an `--experimental-loader` hook.
> **Important:** Any relative file paths will be resolved from the current working directory.
```js
// loadr.mjs
export const loaders = [
"ts-node/esm", // third-party module
"./tests/loader.mjs", // local file
];
```
### requires
Type: `string[]`
A list of files and/or modules to be added as a `--require` hook. Please note that ESM files cannot be loaded via a `require()` statement.
> **Important:** Any relative file paths will be resolved from the current working directory.
```js
// loadr.mjs
export const requires = [
"esm", // third-party module
"dotenv/register", // third-party module
"./tests/setup.js", // local file
];
```
### quiet
Type: `Boolean`
Default: `false`
By default, `loadr` invokes the system bell when your `command` process terminates with a non-zero exit code.
> **Note:** If defined, the `-q` or `--quiet` CLI argument takes precedence over the configuation file.
```js
// loader.mjs
export const quiet = true;
```
## License
MIT © [Luke Edwards](https://lukeed.com)