npm.io
0.1.0 • Published 5 years ago

universal-import.macro

Licence
MIT
Version
0.1.0
Deps
2
Size
6 kB
Vulns
0
Weekly
0
Stars
2

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

Keywords