universal-import.macro
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

universal-import.macro

Babel Macro

Babel macro for automatic conversion of import() call expressions into require() based on a supplied code string.

Why?

Because you want code splitting on the client side, but synchronous imports on the server side.

How?

Add universal-import.macro to your dependencies.

// Before
import(`./assets/${name}.svg`);
// After
import universalImport from "universal-import.macro";

universalImport(`./assets/${name}.svg`, `!!process.env.NO_DYNAMIC_IMPORTS`);

Replace !!process.env.NO_DYNAMIC_IMPORTS with some other code string which evaluates into a boolean at build-time.

Tests?

Yes, some.

License

MIT

/universal-import.macro/

    Package Sidebar

    Install

    npm i universal-import.macro

    Weekly Downloads

    41

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    5.75 kB

    Total Files

    8

    Last publish

    Collaborators

    • wafflepie