unminified-webpack-plugin
raw JSON → 3.0.0 verified Sat Apr 25 auth: no javascript
A webpack plugin that generates unminified copies of JavaScript bundles alongside their minified versions, eliminating the need for two separate webpack runs. Currently at v3.0.0, it supports webpack 4 and 5 with a peer dependency on webpack ^5.36.2. Unlike alternatives that require running webpack twice or using custom scripts, this plugin integrates directly into the webpack plugin system and automatically detects minified filenames (containing 'min'). It works with both JS and CSS assets, supports BannerPlugin, and offers include/exclude filters and a configurable postfix for filenames without 'min'.
Common errors
error Error: Cannot find module 'unminified-webpack-plugin' ↓
cause Plugin not installed or missing from package.json devDependencies.
fix
Run npm install --save-dev unminified-webpack-plugin and ensure it is present in node_modules.
error TypeError: UnminifiedWebpackPlugin is not a constructor ↓
cause Trying to use ESM import pattern without default export interop.
fix
Use require instead: const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
error Error: webpack@5.xx.xx is not compatible with this plugin. ↓
cause Plugin version <3.0.0 does not support webpack 5.
fix
Update to version 3.0.0 or later: npm install unminified-webpack-plugin@latest.
error Output file 'library.js' not generated, only 'library.min.js' exists. ↓
cause Plugin not properly configured or included in webpack plugins array.
fix
Ensure new UnminifiedWebpackPlugin() is added to the plugins array and that optimization.minimize is enabled.
Warnings
breaking Dropped support for webpack 3 and below. Plugin v3.0.0 only supports webpack 4 and 5. ↓
fix Ensure your project uses webpack ^4.0.0 or ^5.36.2.
deprecated The 'nomin' postfix default is deprecated in favor of explicit 'postfix' option. Using 'nomin' may produce unexpected filenames when output.filename does not contain 'min'. ↓
fix Set a custom postfix, e.g., { postfix: 'unmin' }.
gotcha Plugin may not work correctly with webpack's default optimization settings that include minimized output. ↓
fix Ensure webpack mode is set to 'production' or optimization.minimize is enabled. The plugin relies on the presence of minified output.
gotcha Filenames that contain 'min' as part of a word (e.g., 'Admin') are incorrectly treated as minified, leading to missing or malformed unminified copies. ↓
fix Update to the latest version (>=1.4.0) which handles 'ext' properly.
gotcha When using BannerPlugin with older versions, banner info is not applied to the unminified output. ↓
fix Upgrade to v1.4.0 or later.
Install
npm install unminified-webpack-plugin yarn add unminified-webpack-plugin pnpm add unminified-webpack-plugin Imports
- default (UnminifiedWebpackPlugin) wrong
import UnminifiedWebpackPlugin from 'unminified-webpack-plugin';correctconst UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); - UnminifiedWebpackPlugin as class wrong
new UnminifiedWebpackPlugin.postfix('unmin')correctnew UnminifiedWebpackPlugin({ postfix: 'unmin' }) - UnminifiedWebpackPlugin with webpack 5 wrong
new UnminifiedWebpackPlugin({ mode: 'production' })correctconst UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); new UnminifiedWebpackPlugin()
Quickstart
const path = require('path');
const webpack = require('webpack');
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
module.exports = {
mode: 'production',
entry: { index: './src/index.js' },
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'library.min.js'
},
plugins: [
new UnminifiedWebpackPlugin()
]
};