
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
webpack-remove-code-blocks
Advanced tools
A webpack plugin that removes marked blocks of code from any code processed by webpack.
The webpack-remove-code-blocks removes blocks of code marked with special labels.
The loader can be incorporated into the build process to remove the code that you don't want to see in production. It supports the usage of multiple blocks. The loader was originated from Webpack Remove Block.
# NPM
npm install --save-dev webpack-remove-code-blocks
# Yarn
yarn add --dev webpack-remove-code-blocks
Let's start with a simple usage example. For example, we want to remove some code from a bundle while we build a project. To do that, we need to take a few simple steps.
Firstly, we need to add the loader and some additional settings to our webpack configuration:
module.exports = {
module: {
rules: [
{
test: /\.js$/, // files we want to procces
exclude: /(node_modules|bower_components|\.spec\.js)/, // files we want to exclude
use: [
{
loader: 'webpack-remove-code-blocks', // use the loader
},
],
},
],
},
};
Then, we can mark unwanted blocks of code in our .js files using comments with the special syntax devblock:start and devblock:end:
/* devblock:start */
console.log('something not for production');
/* devblock:end */
After the bundling process, the marked blocks will be removed (the comments will be removed too).
Let's suppose, that we have a more sophisticated task. We want to use different labels (we might want to keep some code in staging, but not in the production environment) and process different file extensions. That's not a problem.
The only thing we need to do is to provide some additional settings to our webpack configuration:
module.exports = {
module: {
rules: [
{
test: /\.js|\.ts|\.tsx$/, // files we want to procces
exclude: /(node_modules|bower_components|\.spec\.js)/, // files we want to exclude
use: [
{
loader: 'webpack-remove-code-blocks', // use the loader
options: {
blocks: [ // define three different blocks
'debug',
'devblock',
{
start: 'devblock_start',
end: 'devblock_end',
prefix: '/*',
suffix: '*/',
},
],
},
},
],
},
],
},
};
Let's now build our project with this code inside:
/* debug:start */
console.log('debug');
/* debug:end */
var makeFoo = function(bar, baz) {
// The following code will be removed with the loader
/* devblock:start */
if (bar instanceof Bar !== true) {
throw new Error('makeFoo: bar param is required and must be instance of Bar');
}
/* devblock:end */
/* devblock_start */
if (baz instanceof Baz !== true) {
throw new Error('makeFoo: baz param is required and must be instance of Baz');
}
/* devblock_end */
// This code will remain
return new Foo(bar, baz);
}
After the bundling process, the result will be as follows:
var makeFoo = function(bar, baz) {
// The following code will be removed with the loader
// This code will remain
return new Foo(bar, baz);
}
If you want to define different comment blocks, use the options.blocks array. Each element of the array describes a unique
block of comments to be removed. The block can be described by an object with the following properties:
start: 'dev_start', # a string value that defines the beginning of a block to remove
end: 'dev_end', # a string value that defines the end of a block to remove
prefix: '/*', # a string value that defines the beginning of a comment
suffix: '*/', # a string value that defines the end of a comment
Or, if you don't want to clutter your configuration, a block can be described by just a simple string. The string debug
will represent a block of comments with the following properties:
start: 'debug:start',
end: 'debug:end',
prefix: '/*',
suffix: '*/',
The MIT License (MIT). Please see License File for more information.
FAQs
A webpack plugin that removes marked blocks of code from any code processed by webpack.
The npm package webpack-remove-code-blocks receives a total of 934 weekly downloads. As such, webpack-remove-code-blocks popularity was classified as not popular.
We found that webpack-remove-code-blocks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.