Socket
Book a DemoInstallSign in
Socket

@guardian/shimport

Package Overview
Dependencies
Maintainers
30
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guardian/shimport

Shim for dynamic import()

latest
npmnpm
Version
1.0.2
Version published
Maintainers
30
Created
Source

Shimport

Note, this is the same as https://github.com/Rich-Harris/shimport but exported as an ES module. See that repo for more information on how this works.

Quick start:

You can test for dynamic import support using something like:

try {
    new Function('url', `return import(url)`)
} catch (e) // not supported

Then, to initialise shimport do:

import { initialise } from '@guardian/shimport'
initialise()

You can then call shimport as:

self.__shimport__

I.e. use this in place of 'import' to perform dynamic imports.

Note, the global name is hardcoded unfortunately.

Recommend adding the following types as globals for using this if you are a TS person:

interface Window {
    __shimport__: (url: string) => Promise<any>;
}

Very thankful to @Rich-Harris for the work.

A 3kb (gzipped) shim for import and export. Allows you to use JavaScript modules in all browsers, including dynamic import().

License

LIL

FAQs

Package last updated on 05 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts