Skip to content

Instantly share code, notes, and snippets.

@gsathya
Created March 20, 2017 22:23
Show Gist options
  • Save gsathya/7647bf81374c17782ff306da2e272b50 to your computer and use it in GitHub Desktop.
Save gsathya/7647bf81374c17782ff306da2e272b50 to your computer and use it in GitHub Desktop.
dynamic import
// Original:
import("module/id").then(...);
// Node.js (synchronous require; easy):
Promise.resolve().then(_ => require("module/id")).then(...);
// AMD (async require; non-standard):
new Promise(resolve => require("module/id", resolve)).then(...);
// Webpack 2 (require.ensure is Webpack-specific):
new Promise(resolve => {
require.ensure(["module/id"], require => {
resolve(require("module/id"));
});
}).then(...);
// Meteor 1.5:
module.dynamicImport("module/id").then(…);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment