Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-module-loader

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-module-loader

An ES6 Module Loader shim

  • 0.11.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
decreased by-60.23%
Maintainers
2
Weekly downloads
 
Created
Source

ES6 Module Loader Polyfill Build Status

Dynamically loads ES6 modules in browsers and NodeJS with support for loading existing and custom module formats through loader hooks.

This project implements dynamic module loading through System exactly to the previous ES6-specified loader API at 2014-08-24 ES6 Specification Draft Rev 27, Section 15 and will continue to track this API as it is re-drafted as a browser specification (currently most likely to be at https://github.com/whatwg/loader).

For an overview of build workflows, see the production guide.

For an example of a universal module loader based on this polyfill for loading AMD, CommonJS and globals, see SystemJS.

The current version is tested against Traceur 0.0.79.

Documentation

Getting Started

Download both es6-module-loader.js and traceur.js into the same folder.

If using ES6 syntax (optional), include traceur.js in the page first then include es6-module-loader.js:

  <script src="traceur.js"></script>
  <script src="es6-module-loader.js"></script>

Write an ES6 module:

mymodule.js:

  export class q {
    constructor() {
      console.log('this is an es6 class!');
    }
  }

We can then load the module with the dynamic loader:

<script>
  System.import('mymodule').then(function(m) {
    new m.q();
  });
</script>

The dynamic loader returns a Module object, which contains getters for the named exports (in this case, q).

Module Tag

As well as defining window.System, this polyfill provides support for the <script type="module"> tag:

<script type="module">
  // loads the 'q' export from 'mymodule.js' in the same path as the page
  import { q } from 'mymodule';

  new q(); // -> 'this is an es6 class!'
</script>

Because it is only possible to load ES6 modules with this tag, it is not suitable for production use in this way.

See the demo folder in this repo for a working example demonstrating both module loading the module tag in the browser.

NodeJS Use
  npm install es6-module-loader

For use in NodeJS, the Loader and System globals are provided as exports:

index.js:

  var System = require('es6-module-loader').System;

  System.import('some-module').then(function(m) {
    console.log(m.p);
  });

some-module.js:

  export var p = 'NodeJS test';

Running the application:

> node index.js
NodeJS test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "lib" subdirectory!

Credit

Copyright (c) 2014 Luke Hoban, Addy Osmani, Guy Bedford

License

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 15 Jan 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc