Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexandremasy/umd-fetcher

A basic UMD loader
https://github.com/alexandremasy/umd-fetcher

Last synced: about 1 hour ago
JSON representation

A basic UMD loader

Awesome Lists containing this project

README

        

# UMD Fetcher
> A basic UMD module fetcher.

## Why

Because I can.

While building a large application means some part of the codebase will be irrelevant to the user at a certain moment. Therefor let's only load the part the user need at the right moment. Lazy loading is the key to improve reactivity and happiness of our user.

## How

1. Install the lib: `yarn add umd-fetcher`
2. Use it like so:
```
import UMDFetcher from 'umd-fetcher'

UMDFetcher.fetch({url: 'your-umd-package.umd.min.js', name:'your-umd-package-name'})
.then((module) => {
console.log('module', module);
});
```

## API

`fetch({name , url ):Promise:Module`

Fetch the module from the given url.

The name of the umd module is used to avoid naming collision and prevent multiple loading. It is defined during the build time of the umd module. With webpack it is defined [with the output.library param](https://webpack.js.org/configuration/output/#outputlibrary).

`exists({name }):Boolean`

Check whether or not the module already exists.

`get({name }):Module`

Return the umd module with the given name.

If the module is not found or not loaded, an error will be thrown.