Skip to content

Instantly share code, notes, and snippets.

@vio
Last active October 25, 2017 06:04
Show Gist options
  • Save vio/4a55903aae3053bc99b142de723db373 to your computer and use it in GitHub Desktop.
Save vio/4a55903aae3053bc99b142de723db373 to your computer and use it in GitHub Desktop.
Dynamic imports with Webpack 3 + Typescript 2.4 + Babel

Using import

import(/* webpackChunkName: "my-chunnk" */ 'CHUNK_PATH')
  .then((res) => console.log(res))
  .catch((err) => console.error(err));
  1. supported by TS 2.4, but module will need to output esnext (tsconfig.json)
  2. babel-plugin for syntax (babel-plugin-syntaxt-dynamic-import)

Using System.import (Webpack 2)

import(/* webpackChunkName: "my-chunnk" */ 'CHUNK_PATH')
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

Already supported, though TS will need type def for System (eg: declare const System: any).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment