0.1.1 • Published 3 months ago
enload v0.1.1
enload - universal common loader for JS runtimes
Why?
- Import a variety of configuration formats (YAML, TOML, JSON5)
- Loosen Node's standard enforcement of import assertions for JSON
- Import frontend framework formats for server templating (JSX, Vue, Svelte)
- Import transpiled languages (TypeScript, CoffeeScript)
Install
npm install enload
For the loaders, peer deps must be installed and you will be informed if they're missing. See loaders for supported loaders.
Use
In the terminal
If you run from the terminal, you get both static and dynamic imports.
node --import=enload/register app.js
import config from "./config.json";
// or (await import("./config.json")).default
Programmatically
If you use programmatically, imports coming after the enload()
invocation
must be dynamic (import()
).
import enload from "enload";
enload();
const config = (await import("./config.json")).default;
Configure
This currently applies only programmatically.
You can pass an extensions
object property to remap a given loader to a new
extension. In the following example, the yaml
loader will trigger on .yml
files.
import enload from "enload";
enload({ extensions: { yaml: ".yml" } });
const config = (await import("./config.yml")).default;
Loaders
Name | Extension | Dependency |
---|---|---|
csv | .csv | csv-parse |
json | .json | |
json5 | .json5 | json5 |
toml | .toml | toml |
xml | .xml | xml2js |
yaml | .yaml | yaml |
jsx | .jsx | esbuild |
vue | .vue | vue |
svelte | .svelte | svelte |
typescript | .ts | esbuild |
coffeescript | .coffee | coffeescript |
License
MIT
Contributing
By submitting code you confirm that you are its sole owner and agree to place it under the terms of MIT, see LICENSE.