Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
babel-plugin-replace-imports
Advanced tools
Replaces import statements.
npm install --save-dev babel-plugin-replace-imports
WARNING: this plugin is used only with options.
.babelrc
Add the following line to your .babelrc
file:
{
"plugins": [
["babel-plugin-replace-imports", {
"test": /\/?regexp\//i,
"replacer": "string"
}]
]
}
babel-loader
You can pass options to the babel loader by using the options property (see the babel options):
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
plugins: ["babel-plugin-replace-imports", {
"test": /\/?regexp\//i,
"replacer": "string"
}]
}
}
}
]
}
Name | Type | Description |
---|---|---|
test | RegExp | Regular expression is tested with the import instance. |
replacer | String|Function | A string that replaces the substring specified by the specified test parameter. A number of special replacement patterns are supported (see String.prototype.replace() ). A function to be invoked to create the new substring to be used to replace the matches to the given regexp of the test parameter. The arguments supplied to this function are described in the String.prototype.replace() . |
Options:
{
"plugins": [
["babel-plugin-replace-imports", {
"test": /\.styl$/i,
"replacer": "$&?theme-red"
}]
]
}
In:
import 'reset.styl';
import 'reset';
import './views';
import '../styles.styl';
import styl from '../stylus/common.styl';
Out:
import 'reset.styl?theme-red';
import 'reset';
import './views';
import '../styles.styl?theme-red';
import styl from '../stylus/common.styl?theme-red';
Options:
{
"plugins": [
["babel-plugin-replace-imports", {
"test": /\.styl$/i,
"replacer": [
"$&?theme-red",
"$&?theme-green",
"$&?theme-blue"
]
}]
]
}
In:
import 'reset.styl';
import 'reset';
import './views';
import '../styles.styl';
import styl from '../stylus/common.styl';
Out:
import 'reset.styl?theme-red';
import 'reset.styl?theme-green';
import 'reset.styl?theme-blue';
import 'reset';
import './views';
import '../styles.styl?theme-red';
import '../styles.styl?theme-green';
import '../styles.styl?theme-blue';
import styl from '../stylus/common.styl?theme-red';
import styl from '../stylus/common.styl?theme-green';
import styl from '../stylus/common.styl?theme-blue';
WARNING: only one replacement rule is processed. It depends on order of the option list.
Options:
{
"plugins": [
["babel-plugin-replace-imports", [
{
"test": /\/stylus\//,
"replacer": "/sass/"
}, {
"test": /\.styl$/i,
"replacer": "$&?theme-red"
}
]]
]
}
In:
import 'reset.styl';
import 'reset';
import './views';
import '../styles.styl';
import styl from '../stylus/common.styl';
Out: For each import statement was done only one replacement rule.
import 'reset.styl?theme-red';
import 'reset';
import './views';
import '../styles.styl?theme-red';
import styl from '../sass/common.styl';
FAQs
Replace import statements
The npm package babel-plugin-replace-imports receives a total of 5,603 weekly downloads. As such, babel-plugin-replace-imports popularity was classified as popular.
We found that babel-plugin-replace-imports demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.