Skip to content

Repository files navigation

esload

JavaScript module loader

Why?

  • Import a variety of configuration formats (YAML, TOML, JSON5)
  • Import frontend framework formats for server-side templating (JSX, Vue, Svelte, Solid, Handlebars, Marko)
  • Import transpiled languages (TypeScript, CoffeeScript)
  • Other stuff (.txt files as string, .wasm modules)

Install

npm install esload

esload comes bundled with the dependency-free loaders for .txt, .json and .wasm. For additional loaders, consult the loader overview on which packages to install.

Use

In the terminal

If you run from the terminal, you get both static and dynamic imports.

node --import=esload app.js

importconfigfrom"./config.json";// or (await import("./config.json")).default

Programmatically

If used programmatically, imports coming after esload() must be dynamic (import()).

importregisterfrom"esload/register";register();constconfig=(awaitimport("./config.json")).default;

Configure

If esload detects an esload.config.js file in the package root, it will load it automatically.

esload.config.js

importyamlfrom"@esload/yaml";exportdefault{loaders: [yaml],virtuals: {"/config.yaml": 'foo: "bar"',},};

loaders

Array property for additional loaders.

importyamlfrom"@esload/yaml";exportdefault{loaders: [yaml],};

virtuals

Object property in the form of { [path]: code } to load from memory instead of the filesystem. Memory paths have precedence over filesystem paths.

exportdefault{virtuals: {// even if `/config.json` exists, it won't be loaded from disk"/config.json": '{ "foo": "bar" }',},};

Loaders

NamePackageDependencies
textesload-
jsonesload-
wasmesload-
csv@esload/csvcsv-parse
json5@esload/json5json5
toml@esload/tomltoml
xml@esload/xmlxml2js
yaml@esload/yamlyaml
react@esload/reactesbuild
vue@esload/vuevue
svelte@esload/sveltesvelte
solid@esload/solidbabel-present-solid@babel/core
handlebars@esload/handlebarshandlebars
marko@esload/markomarko
typescript@esload/typescriptesbuild
coffeescript@esload/coffescriptcoffeescript

License

MIT

Contributing

By contributing to esload, you agree that your contributions will be licensed under its MIT license.

About

JavaScript module loader

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages