Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/alexandremasy/umd-fetcher
- Owner: alexandremasy
- License: mit
- Created: 2020-07-29T13:04:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-01T05:43:17.000Z (over 3 years ago)
- Last Synced: 2024-12-07T00:12:56.386Z (19 days ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
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.