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

babel-plugin-replace-dynamic-import-runtime

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-replace-dynamic-import-runtime

Babel plugin to replace import() with require() at runtime, for node Edit

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Replace dynamic import() with require() at runtime

babel-plugin-replace-dynamic-import-runtime

Babel plugin to replace import(...) with require(...) at runtime, for node (also works with await import(...))

Use case

This has a very narrow use case: when you want to parse the same file for both browser and node (using babel/webpack) and still be able to use webpack's code splitting ability.

This is basically a utility to help reduce code duplication.

So statements like:

...
const someDynamicImport = import('../path/to/your/module');
...

into a require statement that node can understand:

const someDynamicImport = require('../path/to/your/module');

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

Installation

yarn add babel-plugin-replace-dynamic-import-runtime --dev

Usage

.babelrc

{
  "plugins": ["replace-dynamic-import-runtime"]
}

Via CLI

$ babel --plugins replace-dynamic-import-runtime script.js

Via Node API

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

Keywords

FAQs

Package last updated on 11 Oct 2017

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