Socket
Socket
Sign inDemoInstall

babel-plugin-dynamic-import-node

Package Overview
Dependencies
15
Maintainers
9
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-dynamic-import-node

Babel plugin to transpile import() to a deferred require(), for node


Version published
Maintainers
9
Weekly downloads
5,987,426
decreased by-9.08%

Weekly downloads

Package description

What is babel-plugin-dynamic-import-node?

The babel-plugin-dynamic-import-node package is a Babel plugin that transpiles the ECMAScript dynamic import() syntax to a deferred require() call. This transformation allows for code splitting and dynamic module loading in environments that do not natively support the import() syntax. It is particularly useful for server-side applications or tests running in Node.js where dynamic import is not available or practical.

What are babel-plugin-dynamic-import-node's main functionalities?

Transpile import() to require()

This feature allows developers to use the dynamic import() syntax in their code, which babel-plugin-dynamic-import-node will transpile into a deferred require() call. This enables dynamic module loading and code splitting in environments that do not support import() natively.

import('path/to/module').then(module => {\n  // Use module\n});

Other packages similar to babel-plugin-dynamic-import-node

Readme

Source

babel-plugin-dynamic-import-node

Babel plugin to transpile import() to a deferred require(), for node. Matches the proposed spec.

NOTE: Babylon >= v6.12.0 is required to correctly parse dynamic imports.

Installation

npm install babel-plugin-dynamic-import-node --save-dev

Usage

.babelrc

{
  "plugins": ["dynamic-import-node"]
}
Options
  • noInterop - A boolean value, that if true will not interop the require calls. Useful to avoid using require('module').default on commonjs modules.
{
  "plugins": [
    ["dynamic-import-node", { "noInterop": true }]
  ]
}

Via CLI

$ babel --plugins dynamic-import-node script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['dynamic-import-node']
});

Code Example

Promise.all([
  import('./lib/import1'),
  import('./lib/import2')
 ]).then(([
   Import1,
   Import2
  ]) => {
   console.log(Import1);
   /* CODE HERE*/
  });

Keywords

FAQs

Last updated on 21 Apr 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc