Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
rollup-plugin-inject
Advanced tools
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.
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'
}
})
]
};
The rollup-plugin-replace package allows you to replace strings in files while bundling. It is similar to rollup-plugin-inject in that it can be used to inject code, but it works by replacing specific strings rather than injecting variables or modules.
The rollup-plugin-alias package allows you to create module aliases, which can be used to simplify import statements. While it doesn't inject variables or modules directly, it can be used to achieve similar results by aliasing modules to shorter or more convenient paths.
The rollup-plugin-commonjs package converts CommonJS modules to ES6, so they can be included in a Rollup bundle. It is similar to rollup-plugin-inject in that it helps manage module imports, but it focuses on compatibility with CommonJS modules.
experimental, depends on unreleased version of Rollup
Scan modules for global variables and inject import
statements where necessary
npm install --save-dev rollup-plugin-inject
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
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 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(...)
1.0.0
FAQs
Scan modules for global variables and inject `import` statements where necessary
The npm package rollup-plugin-inject receives a total of 328,968 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.