JSPM

esm-loader

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 304
  • Score
    100M100P100Q97944F
  • License Apache-2.0

A ESM Loader for NodeJS and Browsers Allows to import modules from any source is extendible via modules.

Package Exports

  • esm-loader

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (esm-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Usage

Inside NodeJS with modules support

// The exported fetch is cross environment Nodejs and Browser
import { strToESM, fetch ,fetchImport, dynamicImport } from 'esm-loader/loader.mjs'

// Creates a dynamic import from a string
// Returns a ESM Module with exports from string has resovle for Bare and Absolut Specifiers
// can easy be rewritten for your own extensions
fetchImport('url') //is a shortHand helper for fetch('https://url.to/your/js.mjs').then(strToESM)
    .then(mod=>console.log(mod))

dynamicImport('url') // uses import in the browser and fetchImport in nodejs

inside browser for custom elements or scripts

import { strToESM, dynamicImport } from 'esm-loader/loader.mjs'

// Creates a dynamic import from a string

// can easy be rewritten for your own extensions
fetch('https://url.to/your/js.mjs')
    .then(strToESM)
    /**
     *  Returns a ESM Module with exports from string 
     *  has resolve for Bare and Absolut Specifiers
     *  Your Can Easy rewrite the String that you get from 
     *  fetch befor you use it as input to strToESM.
     */
    .then(mod=>console.log(mod))

dynamicImport('url') // uses import in the browser and fetchImport in nodejs