0.1.0 • Published 3 years ago

universal-import.macro v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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