Webpack Avoid Minification - Development Configuration Guide
Mahesh Waghmare Disabling minification in Webpack during development improves debugging, preserves code readability, and speeds up builds. This guide covers all methods to avoid minification in Webpack.
Introduction
Why Disable Minification?
- Easier debugging
- Readable code in browser
- Faster builds
- Better error messages
- Source map accuracy
When to Disable:
- Development environment
- Debugging issues
- Learning Webpack
- Testing builds
Development Mode
Set Mode to Development
webpack.config.js:
module.exports = {
mode: 'development',
// ... other config
};
Or via CLI:
webpack --mode development
package.json:
{
"scripts": {
"dev": "webpack --mode development"
}
}
Effects:
- Disables minification
- Enables source maps
- Optimizes for development
- Faster builds
Optimization Settings
Disable Minimize
module.exports = {
optimization: {
minimize: false
}
};
Complete Optimization Disable
module.exports = {
optimization: {
minimize: false,
usedExports: false,
sideEffects: false
}
};
Conditional Based on Mode
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
optimization: {
minimize: isProduction
}
};
Minification Plugins
TerserPlugin Configuration
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: false,
mangle: false,
output: {
beautify: true,
comments: true
}
}
})
]
}
};
Disable TerserPlugin
module.exports = {
optimization: {
minimizer: []
}
};
Source Maps
Enable Source Maps
module.exports = {
devtool: 'source-map',
// or
devtool: 'eval-source-map'
};
Options:
source-map- Full source mapeval-source-map- Fast, good for developmentcheap-module-source-map- Faster, less accurate
Conditional Configuration
Environment-Based Config
const isDevelopment = process.env.NODE_ENV !== 'production';
module.exports = {
mode: isDevelopment ? 'development' : 'production',
optimization: {
minimize: !isDevelopment
},
devtool: isDevelopment ? 'eval-source-map' : 'source-map'
};
Separate Config Files
webpack.dev.js:
module.exports = {
mode: 'development',
optimization: {
minimize: false
}
};
webpack.prod.js:
module.exports = {
mode: 'production',
optimization: {
minimize: true
}
};
Best Practices
1. Use Development Mode
Always use mode: 'development' for development builds.
2. Enable Source Maps
devtool: 'eval-source-map'
3. Separate Configs
Use separate config files for dev and production.
4. Environment Variables
const isDev = process.env.NODE_ENV === 'development';
5. Fast Refresh
Enable fast refresh for better development experience.
Quick Reference
Disable Minification:
optimization: { minimize: false }
Development Mode:
mode: 'development'
Source Maps:
devtool: 'eval-source-map'
Conclusion
Avoiding minification in Webpack:
- Use development mode - Simplest method
- Disable optimization -
minimize: false - Enable source maps - For debugging
- Separate configs - Dev vs production
- Use environment variables - Conditional config
Key Points:
mode: 'development'disables minificationoptimization.minimize: falseexplicitly disables- Enable source maps for debugging
- Use separate configs for clarity
- Minify only in production
Proper Webpack configuration improves development workflow and debugging experience.
Written by Mahesh Waghmare
I bridge the gap between WordPress architecture and modern React frontends. Currently building tools for the AI era.
Follow on Twitter →