@ridestore/babel-plugin-dynamic-import-node-sync

1.0.5 • Public • Published

babel-plugin-dynamic-import-node-sync

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

I am using it for server-side rendering.

Difference from babel-plugin-dynamic-import-node

babel-plugin-dynamic-import-node-sync

import(SOURCE) => () => { const r=require(SOURCE);r.then(cb=>cb(r));return r; }()

babel-plugin-dynamic-import-node

import(SOURCE) => Promise.resolve().then(() => require(SOURCE))

Installation

$ npm install @ridestore/babel-plugin-dynamic-import-node-sync --save-dev

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": [
    ["@ridestore/babel-plugin-dynamic-import-node-sync", { "target": "sync" }]
  ]
}

Options

opts.target

Script is looking for import() with comment provided in target field, example:

// .babelrc
{
  "plugins": [
    ["@ridestore/babel-plugin-dynamic-import-node-sync", { "target": "sync" }]
  ]
}

// index.js
const component = import(/* sync */ './path/to/component').then(module => module.MyComponent);
// will be replaced with
const component = (()=>{const r=__webpack_require__(666);r.then=cb=>cb(r);return r;})().then(module => module.MyComponent);

Otherwise, if you initiate plugin without target option, it replaces all import() calls

Package Sidebar

Install

npm i @ridestore/babel-plugin-dynamic-import-node-sync

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

8.29 kB

Total Files

8

Last publish

Collaborators

  • davidstorm
  • adiwani
  • nastia.koval
  • eric.ridestore
  • joakim.ridestore
  • luddilo
  • vilhelm
  • antonbes
  • studentivan
  • snego
  • asmirnov206
  • linushellberg
  • pavvell