# import-to-inlined-require-babel-plugin

> Used to converted import statements into an inline require statements. Useful when trying to avoid requiring modules that are eventually unused in a particular code path and without using a bundler for tree shaking.

Latest version **1.0.1** (published 2022-12-30) · ISC license · 0 weekly downloads

## Install

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

## 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.1 |
| Published | 2022-12-30 |
| First published | 2022-12-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lirancr |

## Links

- npm: https://www.npmjs.com/package/import-to-inlined-require-babel-plugin
- npm.io page: https://npm.io/package/import-to-inlined-require-babel-plugin

## Dependencies (1)

- [@babel/types](https://npm.io/package/@babel/types.md) ^7.20.7

## Recent versions

- 1.0.1 (latest) — 2022-12-30
- 1.0.0 — 2022-12-30

## README

# Import to Inline Require - babel plugin

Used to converted import statements into an inline require statements. 
Useful when trying to avoid requiring modules that are eventually unused in a particular code path and without using a bundler for tree shaking.

By converting each import statement into it's inlined require statement equivalent your code load only the necessary modules for it's runtime operation.

For example if plugin is applied to the code:
```javascript
import { mapKeys } from 'lodash'

let myObj = {...}
if (someCondition) {
    myObj = mapKeys(myObj, (v, k) => v)
}
```

the output will be
```javascript

let myObj = {...}
if (someCondition) {
    myObj = require('lodash').mapKeys(myObj, (v, k) => v)
}
```

and so `lodash` module will not be loaded unless `someCondition` is actually true.

### conversion examples

1. namespace imports
    ```javascript
    import { namespace } from 'module'
    
    const value = namespace
    ```
    
    ```javascript
    const value = require('module').namespace
    ```

2. renamed namespace imports
    ```javascript
    import { namespace as somethingElse } from 'module'
    
    const value = namespace
    ```

    ```javascript
    const value = require('module').namespace
    ```

3. all namespaces imports
    ```javascript
    import * as allNamespace from 'module'
    
    const value = allNamespace
    ```
    
    ```javascript
    const value = require('module')
    ```

4. default import
    ```javascript
    import allNamespace from 'module'
    
    const value = allNamespace
    ```

    ```javascript
    const value = require('module').default
    ```

### Configuration options

| name               | type                 | default | description                                                             |
|--------------------|----------------------|---------|-------------------------------------------------------------------------|
| verbose            | Boolean              | false   | Toggle verbose logging                                                  |
| excludeFiles       | Array<String/RegExp> | [ ]     | Skip replacing import statements in certain files                       |
| excludeModules     | Array<String/RegExp> | [ ]     | Skip replacing import statements of certain modules in all files        |
| naiveStringReplace | Boolean              | false   | Use string literal value when modifying code instead of using AST nodes |

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