dynamic-import-support
transform dynamic imports for node.js
Last updated 3 years ago by goto-bus-stop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dynamic-import-support 
SYNC missed versions from official npm registry.

dynamic-import-support

enable dynamic imports in node.js

import('./whatever').then(function (exports) {
  console.log(exports)
})

npm travis standard

Install

npm install dynamic-import-support

Usage

Use dynamic-import-support/register to enable import() in all modules loaded after the current one:

require('dynamic-import-support/register')

Use dynamic-import-support to transform some source code containing import() calls:

var dynamicImport = require('dynamic-import-support')

dynamicImport(`
  import('./whatever').then(function (exports) {
    console.log(exports)
  })
`) === `
function _import(p){return Promise.resolve().then(function(){return require(p)})}

  _import('./whatever').then(function (exports) {
    console.log(exports)
  })
`

It uses js-tokens instead of a full parser, so it's very quick. Some patterns aren't supported though. For example, import() inside a template string won't be transformed. If this is a problem, please open an issue and we'll figure out how to make it work :)

License

MIT

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |