Socket
Socket
Sign inDemoInstall

@rollup/plugin-inject

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-inject

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


Version published
Weekly downloads
877K
decreased by-14.22%
Maintainers
4
Weekly downloads
 
Created

What is @rollup/plugin-inject?

@rollup/plugin-inject is a Rollup plugin that allows you to automatically inject variables or modules into your bundle. This can be useful for polyfilling global variables, injecting dependencies, or providing shims for certain environments.

What are @rollup/plugin-inject's main functionalities?

Injecting Global Variables

This feature allows you to inject global variables into your bundle. In this example, the `$` variable is automatically injected and mapped to the `jquery` module.

const inject = require('@rollup/plugin-inject');

module.exports = {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    inject({
      $: 'jquery'
    })
  ]
};

Injecting Multiple Variables

This feature allows you to inject multiple variables into your bundle. In this example, both `$` and `_` are injected and mapped to `jquery` and `lodash` respectively.

const inject = require('@rollup/plugin-inject');

module.exports = {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    inject({
      $: 'jquery',
      _: 'lodash'
    })
  ]
};

Injecting Custom Code

This feature allows you to inject custom code or modules into your bundle. In this example, `customVar` is injected and mapped to `src/customModule.js`.

const inject = require('@rollup/plugin-inject');

module.exports = {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    inject({
      include: '**/*.js',
      exclude: 'node_modules/**',
      modules: {
        customVar: 'src/customModule.js'
      }
    })
  ]
};

Other packages similar to @rollup/plugin-inject

Keywords

FAQs

Package last updated on 15 Oct 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc