filter-chunk-webpack-plugin
raw JSON → 3.0.0 verified Sat Apr 25 auth: no javascript
A webpack plugin (v3.0.0) that filters and excludes assets from final output before emission, using flexible pattern rules (glob, RegExp, or custom functions). Supports include/exclude modes, debug logging, and pipelined rule processing. Requires Node >=20 and webpack ^5, ships TypeScript types. Differentiated by its rule-based pipeline and support for async filter functions. Releases are stable with irregular cadence.
Common errors
error TypeError: FilterChunkWebpackPlugin is not a constructor ↓
cause Using named import instead of default import or CJS destructuring incorrectly.
fix
Use 'import FilterChunkWebpackPlugin from ...' (ESM) or 'const FilterChunkWebpackPlugin = require(...)' (CJS).
error Error: Cannot find module 'filter-chunk-webpack-plugin' ↓
cause Package not installed or Node version incompatible (<20).
fix
Run 'npm install filter-chunk-webpack-plugin --save-dev' and ensure Node >=20.
error ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema. ↓
cause Passing invalid options to the plugin constructor.
fix
Ensure options object has correct keys (mode, rules, debug) and rules follow the Rule schema.
error TypeError: Cannot read properties of undefined (reading 'length') ↓
cause Using an async pattern function without awaiting the plugin's apply method or not returning a boolean.
fix
Pattern functions can be async; ensure they return a boolean or Promise<boolean>.
Warnings
breaking Version 3.0.0 requires Node >=20 and webpack ^5.0.0. ↓
fix Ensure Node.js >=20 and webpack ^5 are installed.
breaking Version 2.0.0 dropped Node v6 support and upgraded to webpack 4 compat. ↓
fix Update Node to >=8 or migrate to v3+ for Node >=20.
gotcha Rules are processed as a pipeline in exclude mode; order matters. Each rule filters from the remaining assets. ↓
fix Arrange rules in intended order, especially when combining exclude and include patterns across multiple rules.
gotcha In include mode, rules are combined with OR logic (union). Assets matching any rule are kept. ↓
fix Ensure include rules are not contradictory; consider using exclude mode with negative patterns instead.
deprecated No known deprecations; the plugin is stable with minimal updates.
Install
npm install filter-chunk-webpack-plugin yarn add filter-chunk-webpack-plugin pnpm add filter-chunk-webpack-plugin Imports
- FilterChunkWebpackPlugin wrong
const FilterChunkWebpackPlugin = require('filter-chunk-webpack-plugin').defaultcorrectimport FilterChunkWebpackPlugin from 'filter-chunk-webpack-plugin' - FilterChunkWebpackPlugin wrong
const { FilterChunkWebpackPlugin } = require('filter-chunk-webpack-plugin')correctconst FilterChunkWebpackPlugin = require('filter-chunk-webpack-plugin') - FilterChunkWebpackPlugin (type) wrong
import { FilterChunkWebpackPlugin } from 'filter-chunk-webpack-plugin'correctimport type FilterChunkWebpackPlugin from 'filter-chunk-webpack-plugin'
Quickstart
import FilterChunkWebpackPlugin from 'filter-chunk-webpack-plugin';
export default {
// ... webpack config
plugins: [
new FilterChunkWebpackPlugin({
rules: [
{
patterns: '*.map', // remove all .map files
},
],
}),
],
};