emit-changed-only-webpack-plugin
raw JSON → 2.1.4 verified Sat Apr 25 auth: no javascript
Webpack production plugin that prevents identical output files from being re-emitted after a rebuild, preserving cache headers (ETag, Last-Modified) for unchanged assets. Current stable version 2.1.4 requires webpack ^4.0.0. Key differentiator: focuses on file emission behavior rather than chunk-level comparison, using [contenthash] to detect changes. Helps improve browser caching and V8 code caching by avoiding unnecessary file modifications. Ships TypeScript types.
Common errors
error TypeError: plugin is not a constructor ↓
cause Importing as ES module named import or using wrong require path.
fix
Use const EmitChangedOnlyPlugin = require('emit-changed-only-webpack-plugin');
error Cannot find module 'emit-changed-only-webpack-plugin' ↓
cause Package not installed or misspelled npm package name.
fix
npm install emit-changed-only-webpack-plugin --save-dev
error Error: Webpack mode must be 'production' ↓
cause Plugin enforces production mode by default.
fix
Set mode: 'production' or pass production: false in plugin options.
error Error: No output filename with [contenthash] found ↓
cause Output filename does not contain [contenthash].
fix
Add [contenthash] to output.filename, e.g., '[name].[contenthash].js'.
Warnings
gotcha Plugin requires [contenthash] in output filename; without it, file comparison is unreliable and plugin may emit all files every build. ↓
fix Add [contenthash] to output.filename, e.g., '[name].[contenthash].js'.
gotcha Production mode is enforced by default. If mode is not 'production', plugin will skip logic and may not behave as expected. ↓
fix Set mode: 'production' in webpack config, or pass production: false in plugin options.
gotcha The plugin removes outdated files in the output directory. Any files that are not produced by webpack and not excluded may be deleted. ↓
fix Add patterns to exclude option to protect non-plugin files, e.g., exclude: /\.(txt|png)$/i.
gotcha Using splitChunks: false will disable chunk splitting optimization; only the entry chunk is emitted. Default is true. ↓
fix If you want chunk splitting, keep splitChunks: true (default). Set to false only if you know you don't need it.
Install
npm install emit-changed-only-webpack-plugin yarn add emit-changed-only-webpack-plugin pnpm add emit-changed-only-webpack-plugin Imports
- EmitChangedOnlyPlugin wrong
import EmitChangedOnlyPlugin from 'emit-changed-only-webpack-plugin'correctconst EmitChangedOnlyPlugin = require('emit-changed-only-webpack-plugin') - default wrong
import { EmitChangedOnlyPlugin } from 'emit-changed-only-webpack-plugin'correctimport EmitChangedOnlyPlugin from 'emit-changed-only-webpack-plugin' - EmitChangedOnlyPlugin wrong
new EmitChangedOnlyPlugin()correctnew EmitChangedOnlyPlugin({ exclude: /\.html$/i })
Quickstart
const EmitChangedOnlyPlugin = require('emit-changed-only-webpack-plugin');
module.exports = {
output: {
path: './dist',
filename: '[name].[contenthash].js'
},
plugins: [
new EmitChangedOnlyPlugin({
exclude: /\.html$/i
})
]
};