Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
modify-source-webpack-plugin
Advanced tools
Webpack plugin for modifying modules source.
Webpack Version | Plugin version | Status |
---|---|---|
^5.0.0 | ^4.0.0 | ✅ |
^4.37.0 | ^4.0.0 | ✅ |
npm i -D modify-source-webpack-plugin
yarn add -D modify-source-webpack-plugin
import { ModifySourcePlugin } from 'modify-source-webpack-plugin';
const { ModifySourcePlugin } = require('modify-source-webpack-plugin');
webpack.config.js
module.exports = {
plugins: [new ModifySourcePlugin(options)]
};
rules[].test
Type: RegExp | ((module: webpack.NormalModule) => boolean)
Required
test
is RegExp or function, which used to determinate which modules should be modified.
RegExp
will be applied to full module path (based on userRequest
).
function
will be applied to NormalModule
.
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /index\.js$/
}
]
})
];
plugins: [
new ModifySourcePlugin({
rules: [
{
test: module =>
module.source().source().includes('my-secret-module-marker')
}
]
})
];
rules[].operations
Type: AbstractOperation[]
(supported ConcatOperation
, ReplaceOperation
)
Required
List of operations which describes how modules should be modified.
:warning: Operations should make syntax compatible changes. For example all unsupported syntax will break your build or create errors in runtime.
import {
ModifySourcePlugin,
ConcatOperation
} from 'modify-source-webpack-plugin';
module.exports = {
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-file\.js$/,
operations: [
new ConcatOperation(
'start',
'// Proprietary and confidential.\n\n'
),
new ConcatOperation(
'end',
'\n\n// File is written by me, January 2022'
)
]
}
]
})
]
};
import {
ModifySourcePlugin,
ReplaceOperation
} from 'modify-source-webpack-plugin';
module.exports = {
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-file\.js$/,
operations: [
new ReplaceOperation('once', 'searchValue', 'replaceValue'),
new ReplaceOperation('all', 'searchValue', 'replaceValue')
]
}
]
})
]
};
module.exports = {
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-file\.js$/,
operations: [
new ConcatOperation('start', 'Haha I break your build LOL')
]
}
]
})
]
};
debug
Type: boolean
For easier debugging. Print some logs in the console.
Constants related to information about files that we change.
Constant | Description |
---|---|
$FILE_PATH | Path to file |
$FILE_NAME | File name |
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-file\.js$/,
operations: [
new ConcatOperation(
'end',
'\n\n // This file is on the path - $FILE_PATH and filename - $FILE_NAME'
)
]
}
]
})
];
console.log('Hello world!');
webpack.config.js
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-file\.js$/,
operations: [
new ConcatOperation('start', '// Something before file contents.\n'),
new ConcatOperation('end', '\n// Something after file contents.')
]
}
]
})
];
// Something before file contents.
console.log('Hello world!');
// Something after file contents.
function HelloMessage(props) {
return (
<div>
Hello, $NAME
<button
onClick={() => {
props.userLogout();
alert('Goodbye, $NAME!');
}}
>
$EXIT_LABEL
</button>
</div>
);
}
webpack.config.js
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-component\.jsx$/,
operations: [
new ReplaceOperation('all', '$NAME', 'Artem Batura'),
new ReplaceOperation('once', '$EXIT_LABEL', 'Exit')
// new ReplaceOperation('once', '$EXIT_LABEL', 'Leave')
]
}
]
})
];
function HelloMessage(props) {
return (
<div>
Hello, Artem Batura
<button
onClick={() => {
props.userLogout();
alert('Goodbye, Artem Batura!');
}}
>
Exit
</button>
</div>
);
}
function HelloMessage(props) {
$MY_DEBUG_CODE;
return (
<div>
Hello, user! $MY_USER_COMPONENT
<button onClick={() => props.userLogout()}>Exit</button>
</div>
);
}
webpack.config.js
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /my-component\.js$/,
operations: [
new ReplaceOperation(
'once',
'$MY_DEBUG_CODE',
'console.log("props", props)'
),
new ReplaceOperation(
'once',
'$MY_USER_COMPONENT',
'<div>compilation-time markup</div>'
)
]
}
]
})
];
function HelloMessage(props) {
console.log('props', props);
return (
<div>
Hello, user!
<div>compilation-time markup</div>
<button onClick={() => props.userLogout()}>Exit</button>
</div>
);
}
FAQs
Webpack plugin for modifying modules source
We found that modify-source-webpack-plugin 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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.