# rollup-plugin-inject

> Scan modules for global variables and inject `import` statements where necessary

Latest version **3.0.2** (published 2019-10-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rollup-plugin-inject
pnpm add rollup-plugin-inject
yarn add rollup-plugin-inject
bun add rollup-plugin-inject
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2019-10-29 |
| First published | 2015-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 77 |
| Author | Rich Harris |
| Maintainers | btd, guybedford, lukastaegert, rich_harris |
| Keywords | rollup, rollup-plugin, es2015, npm, modules |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-inject
- Repository: https://github.com/rollup/rollup-plugin-inject
- Homepage: https://github.com/rollup/rollup-plugin-inject#readme
- Issues: https://github.com/rollup/rollup-plugin-inject/issues
- npm.io page: https://npm.io/package/rollup-plugin-inject

## Dependencies (3)

- [magic-string](https://npm.io/package/magic-string.md) ^0.25.3
- [estree-walker](https://npm.io/package/estree-walker.md) ^0.6.1
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.8.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2019-10-29
- 3.0.1 — 2019-07-24
- 3.0.0 — 2019-06-12
- 2.2.0 — 2018-07-26
- 2.1.0 — 2018-07-25
- 2.0.0 — 2016-09-19
- 1.4.1 — 2016-06-23
- 1.4.0 — 2016-01-07
- 1.3.0 — 2015-12-27
- 1.2.0 — 2015-11-15
- 1.1.1 — 2015-10-28
- 1.1.0 — 2015-10-28
- 1.0.0 — 2015-10-25

## README

# rollup-plugin-inject

Scan modules for global variables and inject `import` statements where necessary

## Archived (Migration to Mono-Repo In-Process)

This repository has been archived and is in the process of being migrated to a new monorepo. Please bear with us as we make this transition. More information to follow.

## Installation

```bash
npm install --save-dev rollup-plugin-inject
```


## Usage

```js
import { rollup } from 'rollup';
import inject from 'rollup-plugin-inject';

rollup({
  entry: 'main.js',
  plugins: [
    inject({
      // control which files this plugin applies to
      // with include/exclude
      include: '**/*.js',
      exclude: 'node_modules/**',

      /* all other options are treated as modules...*/

      // use the default – i.e. insert
      // import $ from 'jquery'
      $: 'jquery',

      // use a named export – i.e. insert
      // import { Promise } from 'es6-promise'
      Promise: [ 'es6-promise', 'Promise' ],

      // use a namespace import – i.e. insert
      // import * as fs from 'fs'
      fs: [ 'fs', '*' ],

      // use a local module instead of a third-party one
      'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),

      /* ...but if you want to be careful about separating modules
         from other options, supply `options.modules` instead */

      modules: {
        $: 'jquery',
        Promise: [ 'es6-promise', 'Promise' ],
        'Object.assign': path.resolve( 'src/helpers/object-assign.js' )
      }
    })
  ]
}).then(...)
```

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