webpack-remove-code-blocks
raw JSON → 0.10.1 verified Sat Apr 25 auth: no javascript
A webpack loader plugin that removes blocks of code marked with special comment labels (e.g., `/* devblock:start */.../* devblock:end */`) from files processed by webpack. Current stable version 0.10.1 supports webpack >=3.0.0 and Node.js >=18. It allows multiple named block definitions, optional replacement text, and modes to skip removal based on webpack's `mode` option. Differentiates from alternatives by supporting custom labels, prefixes, and suffixes, and being actively maintained.
Common errors
error Module not found: Error: Can't resolve 'webpack-remove-code-blocks' ↓
cause Loader name typo or missing npm install.
fix
Run
npm install --save-dev webpack-remove-code-blocks and ensure the loader name is exactly 'webpack-remove-code-blocks'. error TypeError: loader is not a function ↓
cause Using require() result as a constructor or plugin instead of a loader string.
fix
Use loader: 'webpack-remove-code-blocks' in the webpack rule, not as a plugin or function.
error No blocks removed from output ↓
cause Missing `blocks` options or wrong comment syntax.
fix
Add
options: { blocks: ['devblock'] } to the rule and use correct comment syntax: /* devblock:start */ ... /* devblock:end */. error Error: Mode removal not working ↓
cause Mode option expects array of webpack mode strings; may be misconfigured.
fix
Check docs: mode value should be an array like
['development'] to skip removal in that mode. Warnings
breaking Version 0.9.0 drops support for Node.js 16 and contains massive refactoring; may break older configs. ↓
fix Upgrade to v0.10.1 or ensure Node.js >=18. Check block definitions as option format may have changed.
breaking Version 0.9.0 changes versioning and is described as a 'candidate for the initial release'; may introduce incompatibilities with earlier v0.1.x. ↓
fix Review changelog for breaking changes; update block options if using custom start/end labels.
deprecated Node.js 16 support dropped in v0.9.0. ↓
fix Use Node.js >=18 for v0.9.0+.
gotcha Loader name is 'webpack-remove-code-blocks' not 'webpack-remove-block' (similar package). ↓
fix Verify spelling in webpack config; use 'webpack-remove-code-blocks'.
gotcha If no `blocks` option provided, default blocks may not be defined; the loader may process nothing. ↓
fix Always specify at least one block label (e.g., `blocks: ['devblock']`).
Install
npm install webpack-remove-code-blocks yarn add webpack-remove-code-blocks pnpm add webpack-remove-code-blocks Imports
- default export (plugin instance) loader function wrong
Use via require('webpack-remove-code-blocks') as a constructor or class.correctmodule.exports = { module: { rules: [ { test: /\.js$/, use: 'webpack-remove-code-blocks' } ] } } - loader path in webpack config wrong
loader: require.resolve('webpack-remove-code-blocks')correctloader: 'webpack-remove-code-blocks' - options object for custom blocks wrong
Options passed as a separate argument or via plugin syntax.correctoptions: { blocks: ['debug', { start: 'devblock_start', end: 'devblock_end', prefix: '/*', suffix: '*/' }] }
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'webpack-remove-code-blocks',
options: {
blocks: ['devblock', 'debug']
}
}
]
}
]
}
};
// Input file: app.js
/* devblock:start */
console.log('remove me');
/* devblock:end */
console.log('keep me');
// Output: 'keep me' block only