Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rollup-plugin-inject

Package Overview
Dependencies
Maintainers
4
Versions
13
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 inject `import` statements where necessary

  • 3.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is rollup-plugin-inject?

The rollup-plugin-inject package is a Rollup plugin that allows you to automatically inject variables or modules into your code. This can be useful for polyfills, shims, or any other global variables that you want to ensure are available in your bundle.

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

Injecting Global Variables

This feature allows you to inject global variables into your code. In this example, the $ and _ variables are injected from the 'jquery' and 'lodash' modules 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 from a specific file. In this example, the 'myGlobal' variable is injected from the 'src/myGlobal.js' file.

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

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

Other packages similar to rollup-plugin-inject

Keywords

FAQs

Package last updated on 29 Oct 2019

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