
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@rollup/plugin-inject
Advanced tools
Scan modules for global variables and injects `import` statements where necessary
🍣 A Rollup plugin which scans modules for global variables and injects import statements where necessary.
This plugin requires an LTS Node version (v14.0.0+) and Rollup v1.20.0+.
Using npm:
npm install @rollup/plugin-inject --save-dev
Create a rollup.config.js configuration file and import the plugin:
import inject from '@rollup/plugin-inject';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [
inject({
Promise: ['es6-promise', 'Promise']
})
]
};
Then call rollup either via the CLI or the API.
This configuration above will scan all your files for global Promise usage and plugin will add import to desired module (import { Promise } from 'es6-promise' in this case).
Examples:
{
// import { Promise } from 'es6-promise'
Promise: [ 'es6-promise', 'Promise' ],
// import { Promise as P } from 'es6-promise'
P: [ 'es6-promise', 'Promise' ],
// import $ from 'jquery'
$: 'jquery',
// 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' ),
}
Typically, @rollup/plugin-inject should be placed in plugins before other plugins so that they may apply optimizations, such as dead code removal.
In addition to the properties and values specified for injecting, users may also specify the options below.
excludeType: String | Array[...String]
Default: null
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
includeType: String | Array[...String]
Default: null
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
babel-plugin-transform-define is a Babel plugin that allows you to inject global constants into your code. It is similar to @rollup/plugin-inject but is used within the Babel ecosystem. It is useful for defining environment variables and other constants at build time.
browserify-global-shim is a Browserify plugin that allows you to replace global variables with require calls. It is similar to @rollup/plugin-inject but is used within the Browserify ecosystem. It is useful for shimming global variables and providing polyfills.
FAQs
Scan modules for global variables and injects `import` statements where necessary
The npm package @rollup/plugin-inject receives a total of 3,005,261 weekly downloads. As such, @rollup/plugin-inject popularity was classified as popular.
We found that @rollup/plugin-inject demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.