Remove Source Webpack Plugin
raw JSON → 0.1.1 verified Sat Apr 25 auth: no javascript
A lightweight webpack plugin that removes specified assets from the compilation output, commonly used in conjunction with html-webpack-inline-source-plugin to eliminate inlined source files from the final bundle. The current version is 0.1.1. It accepts regex or an array of regex patterns to match assets for removal. The plugin is available as an npm package under an MIT license.
Common errors
error TypeError: Super expression must either be null or a function ↓
cause Webpack version mismatch (e.g., webpack 3)
fix
Upgrade to webpack 4 or 5.
error ERROR: RemoveSourceWebpackPlugin is not a constructor ↓
cause Attempted to import using named import 'RemoveSourceWebpackPlugin'
fix
Use default import: const RemoveSourceWebpackPlugin = require('remove-source-webpack-plugin');
error Module not found: Error: Can't resolve 'remove-source-webpack-plugin' ↓
cause Package not installed or webpack config path issue
fix
Run
npm install remove-source-webpack-plugin --save-dev. Warnings
gotcha Plugin only works in webpack 4 and 5, not webpack 3. ↓
fix Ensure webpack version is 4 or 5.
gotcha Using an empty array or no patterns removes nothing; patterns must match asset names exactly. ↓
fix Provide regex patterns that match asset filenames, not paths.
gotcha The plugin removes assets from compilation, not from the file system. ↓
fix It works after emit hooks, so removed assets won't appear in output directory.
gotcha Multiple plugins of same type can be added; each removes matching assets. ↓
fix You can add multiple instances with different patterns.
Install
npm install remove-source-webpack-plugin yarn add remove-source-webpack-plugin pnpm add remove-source-webpack-plugin Imports
- RemoveSourceWebpackPlugin wrong
import RemoveSourceWebpackPlugin from 'remove-source-webpack-plugin'correctconst RemoveSourceWebpackPlugin = require('remove-source-webpack-plugin') - default export wrong
const plugin = require('remove-source-webpack-plugin').defaultcorrectconst RemoveSourceWebpackPlugin = require('remove-source-webpack-plugin') - alias import wrong
import { RemoveSourceWebpackPlugin } from 'remove-source-webpack-plugin'correctimport RemoveSourceWebpackPlugin from 'remove-source-webpack-plugin'
Quickstart
const RemoveSourceWebpackPlugin = require('remove-source-webpack-plugin');
module.exports = {
// ... other webpack config
plugins: [
new RemoveSourceWebpackPlugin(/runtime\..*\.js$/),
],
};