# universal-import.macro

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

Latest version **0.1.0** (published 2021-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install universal-import.macro
pnpm add universal-import.macro
yarn add universal-import.macro
bun add universal-import.macro
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-07-07 |
| First published | 2021-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Václav Jančařík |
| Maintainers | wafflepie |
| Keywords | babel-plugin-macros, require, import, dynamic, async |

## Links

- npm: https://www.npmjs.com/package/universal-import.macro
- Repository: https://github.com/wafflepie/universal-import.macro
- Homepage: https://github.com/wafflepie/universal-import.macro#readme
- Issues: https://github.com/wafflepie/universal-import.macro/issues
- npm.io page: https://npm.io/package/universal-import.macro

## Dependencies (2)

- [babel-plugin-macros](https://npm.io/package/babel-plugin-macros.md) ^3.1.0
- [require-from-string](https://npm.io/package/require-from-string.md) ^2.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2021-07-07

## README

# universal-import.macro

[![Babel Macro](https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square)](https://github.com/kentcdodds/babel-plugin-macros)

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.

```js
// Before
import(`./assets/${name}.svg`);
```

```js
// 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](./src/macro.test.js).

## License

MIT

---
_Source: https://npm.io/package/universal-import.macro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
