# babel-plugin-import-to-require

> Translate import statements to require statements

Latest version **1.0.0** (published 2018-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-import-to-require
pnpm add babel-plugin-import-to-require
yarn add babel-plugin-import-to-require
bun add babel-plugin-import-to-require
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-02-21 |
| First published | 2018-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | import, to, require, plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-import-to-require
- Repository: https://github.com/mattdesl/babel-plugin-import-to-require
- Issues: https://github.com/mattdesl/babel-plugin-import-to-require/issues
- npm.io page: https://npm.io/package/babel-plugin-import-to-require

## Dependencies (1)

- [babel-template](https://npm.io/package/babel-template.md) ^6.26.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-02-21

## README

# babel-plugin-import-to-require

Remaps `import` statements to `require()` statements. This is mostly useful alongside later static analysis tools (like glslify), where Babel import inter-op can often make static analysis difficult or impossible.

In:

```js
import foobar from 'foo';
console.log(foobar());
```

Out:

```js
const foobar = require('foo');
console.log(foobar());
```

> :warning: This only handles basic import specifiers (i.e. the above format), and does not support things like wildcard imports, destructuring, namespaces, etc. Feel free to submit a PR if you need this feature.

## Installation

```sh
$ npm install babel-plugin-import-to-require
```

## Usage

The `modules` option can be used to narrow down to a specific list of modules to remap, ignoring all other import statements. If no parameter is specified, _all_ import statements will be remapped.

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": [
    [ "import-to-require", { "modules": [ "foo" ] } ]
  ]
}
```

### Via CLI

```sh
$ babel --plugins import-to-require script.js
```

### Via Node API

```javascript
require('babel').transform('code', {
  plugins: [
    [ 'import-to-require' , { modules: [ 'foo' ] } ]
  ]
});
```

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