All Projects → azu → dynamic-import-assets

azu / dynamic-import-assets

Licence: MIT License
Dynamic Imports for JavaScript and CSS.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to dynamic-import-assets

importtool
General data import tool for IgorPro
Stars: ✭ 19 (-5%)
Mutual labels:  loader, import
Bentools Etl
PHP ETL (Extract / Transform / Load) library with SOLID principles + almost no dependency.
Stars: ✭ 45 (+125%)
Mutual labels:  loader, import
rprogress
React ajax loader progress bar with clear API
Stars: ✭ 12 (-40%)
Mutual labels:  loader
es2postgres
ElasticSearch to PostgreSQL loader
Stars: ✭ 18 (-10%)
Mutual labels:  loader
rollup-loader
Rollup does what it can do, and let Webpack finish the job.
Stars: ✭ 86 (+330%)
Mutual labels:  loader
memory-module-loader
An implementation of a Windows loader that can load dynamic-linked libraries (DLLs) directly from memory
Stars: ✭ 111 (+455%)
Mutual labels:  loader
l2cu
L²CU: LDraw Linux Command line Utility
Stars: ✭ 14 (-30%)
Mutual labels:  import
esbuild-plugin-import-glob
A esbuild plugin which allows to import multiple files using the glob syntax.
Stars: ✭ 28 (+40%)
Mutual labels:  import
assimpjs
The emscripten interface for the assimp library that allows you to import 40+ 3D file formats in the browser.
Stars: ✭ 19 (-5%)
Mutual labels:  import
architectury-api
An intermediary api aimed at easing development of multiplatform mods.
Stars: ✭ 139 (+595%)
Mutual labels:  loader
dts-css-modules-loader
A small Webpack loader to generate typings for your CSS-Modules
Stars: ✭ 44 (+120%)
Mutual labels:  loader
LoadersPack-Android
Android LoadersPack - a replacement of default android material progressbar with different loaders
Stars: ✭ 119 (+495%)
Mutual labels:  loader
nunjucks-loader
Webpack loader for Nunjucks templates
Stars: ✭ 20 (+0%)
Mutual labels:  loader
vue-visual
Vue 2 image and video loader supporting lazy loading, background videos, fixed aspect ratios, low rez poster images, transitions, loaders, slotted content and more.
Stars: ✭ 56 (+180%)
Mutual labels:  loader
python-imphook
Simple and clear import hooks for Python - import anything as if it were a Python module
Stars: ✭ 23 (+15%)
Mutual labels:  import
python-yamlordereddictloader
(DEPRECATED) YAML loader and dumper for PyYAML allowing to keep keys order.
Stars: ✭ 25 (+25%)
Mutual labels:  loader
KVSpinnerView
KVSpinnerView is highly customizable progress HUD
Stars: ✭ 37 (+85%)
Mutual labels:  loader
faker
A kotlin extension to load images asynchronously on android
Stars: ✭ 58 (+190%)
Mutual labels:  loader
CsharpVoxReader
A generic C# reader for MagicaVoxel's vox file format
Stars: ✭ 15 (-25%)
Mutual labels:  loader
zabbix-review-export-import
Clone of zabbix-review-export with added import object(s) feature
Stars: ✭ 36 (+80%)
Mutual labels:  import

dynamic-import-assets

Dynamic Import Assets like JavaScript and CSS.

Feature

  • Dynamic load JavaScript and CSS from URL
  • Support Promises
  • Work with ES modules registry like UNPKG and Pika CDN

Install

Install with npm:

npm install dynamic-import-assets

Usage

Provide these APIs

  • dynamicImportJS: Load JavaScript Script and resolve with loaded <script>
  • dynamicImportCSS: Load CSS Script and resolve with <link>
export declare type Loader<T extends HTMLElement> = (url: string) => Promise<T>;
export declare function createDynamicImportAssetsLoader<T extends HTMLElement>(loader: Loader<T>): (url: string) => Promise<T>;
export declare const dynamicImportJS: (url: string) => Promise<HTMLScriptElement>;
export declare const dynamicImportCSS: (url: string) => Promise<HTMLLinkElement>;

Examples

For example, you want to load https://toast.evila.me/'s js and css using UNPKG, do following:

(async function main(){
    const { dynamicImportCSS } = await import("https://unpkg.com/dynamic-import-assets@^1.0.0?module");
    const { createToast } = await import("https://unpkg.com/@evillt/[email protected]?module");
    // inject <link rel="stylesheet">
    await dynamicImportCSS("https://unpkg.com/@evillt/[email protected]/dist/toast.min.css");
    // use toast after loaded 
    createToast("Hello world");
})();

Also support JavaScript as script loading:

(async function main(){
    const { dynamicImportJS, dynamicImportCSS } = await import("https://unpkg.com/dynamic-import-assets@^1.0.0?module");
    await Promise.all([
        // inject <link rel="stylesheet">
        dynamicImportCSS("https://unpkg.com/@evillt/[email protected]/dist/toast.min.css"),
        // inject <script>
        dynamicImportJS("https://unpkg.com/@evillt/[email protected]")
    ]);
    // use toast after loaded 
    toast.createToast("Hello world");
})();

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].