runtime-import
    TypeScript icon, indicating that this package has built-in type declarations

    2.2.1 • Public • Published

    runtime-import

    TypeScript Build Status Npm Package Downloads

    Import remote resource(js or css) asynchronously.

    Install

    npm i runtime-import --save

    Usage

    importScript

    Import a javascript file, if the file is in UMD format, return it's export object.

    import { importScript } from 'runtime-import'
    
    try {
      const $ = await importScript('//foobar.com/jquery.js')
    } catch (err) {
      console.error(err)
    }

    importStyle

    Import a css file.

    import { importStyle } from 'runtime-import'
    
    try {
      await importStyle('//foobar.com/bootstrap.css')
    } catch (err) {
      console.error(err)
    }

    importModule

    Import a module, if the last javascript file is in UMD format, return it's export object.

    import { importModule } from 'runtime-import'
    
    try {
      const bootstrap = await importModule({
        js: ['//foobar.com/bootstrap.js'],
        css: ['//foobar.com/bootstrap.css']
      })
    } catch (err) {
      console.error(err)
    }

    Install

    npm i runtime-import

    DownloadsWeekly Downloads

    89

    Version

    2.2.1

    License

    MIT

    Unpacked Size

    88 kB

    Total Files

    41

    Last publish

    Collaborators

    • yusangeng